Function useFallback

  • Creates a middleware, that tries to execute a main logger and uses the first working fallback middleware, if it fails, using a 'next function'.

    Parameters

    Returns LoggerMiddleware

    The new middleware.

    Example

    import log, { AsyncLoggerMiddleware, useFallback } from "@egomobile/log"

    const myFirstMiddleware: AsyncLoggerMiddleware = (type, args, done) => {
    try {
    // do your stuff here

    done() // tell the iteration, that we are finished here
    } catch (error) {
    done(error) // you can explicitly tell the iteration
    // that some failed here and we need to execute
    // the upcoming fallback
    }
    }

    // is only called, if 'myFirstMiddleware' fails
    const mySecondMiddleware: AsyncLoggerMiddleware = (type, args, done) => {
    // do your stuff here
    //
    // if something fails here and throws an error
    // it is the same thing as calling 'done(error)'

    done() // tell, that we are OK here
    }

    // is only called, if 'mySecondMiddleware' fails
    const myThirdMiddleware: AsyncLoggerMiddleware = (type, args, done) => {
    // do your stuff here

    done()
    }

    log.use( useFallback(myFirstMiddleware, mySecondMiddleware, myThirdMiddleware) )

    log('foo')

Generated using TypeDoc