Options
All
  • Public
  • Public/Protected
  • All
Menu

@egomobile/log

Index

References

default

Renames and re-exports log

Type aliases

AsyncLoggerMiddleware

AsyncLoggerMiddleware: (type: LogType, args: any[], next: NextFunction) => void

Type declaration

    • An any logger middleware.

      Parameters

      • type: LogType

        The type.

      • args: any[]

        The submitted arguments.

      • next: NextFunction

        The next function.

      Returns void

LogAction

LogAction: (...args: any[]) => void

Type declaration

    • (...args: any[]): void
    • A logger action.

      Parameters

      • Rest ...args: any[]

      Returns void

LoggerFilter

LoggerFilter: (type: LogType, args: any[]) => any

Type declaration

    • A logger middleware.

      Parameters

      • type: LogType

        The type.

      • args: any[]

        The submitted arguments.

      Returns any

      If falsy nothing is logged.

LoggerMiddleware

LoggerMiddleware: (type: LogType, args: any[]) => void

Type declaration

    • A logger middleware.

      Parameters

      • type: LogType

        The type.

      • args: any[]

        The submitted arguments.

      Returns void

NextFunction

NextFunction: (error?: any) => any

Type declaration

    • (error?: any): any
    • A 'next function'.

      Parameters

      • Optional error: any

      Returns any

Variables

log

log: ILogger = ...

The global, default logger.

Functions

consoleLogger

createLogger

  • Creates a new logger instance.

    example
    import { consoleLogger, createLogger, LogType } from "@egomobile/log"

    // create custom logger
    const myLogger = createLogger()

    // add build-in middleware
    myLogger.use(consoleLogger())

    // add one or more custom middlewares
    // for your custom logger
    myLogger.use((type: LogType, args: any[]) => {
    // your code
    })

    // start logging
    myLogger("foo")
    myLogger.error("bar")

    Returns ILogger

    The new instance.

useAll

  • Creates a middleware, that tries to execute all loggers in a chain, using a 'next function'.

    example
    import log, { AsyncLoggerMiddleware, useAll } from "@egomobile/log"

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

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

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

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

    // is called after 'mySecondMiddleware' has
    // called 'next()' without errors
    const myThirdMiddleware: AsyncLoggerMiddleware = (type, args, done) => {
    // do your stuff here

    done()
    }

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

    log('foo')

    Parameters

    Returns LoggerMiddleware

    The new middleware.

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'.

    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')

    Parameters

    Returns LoggerMiddleware

    The new middleware.

useFilter

  • Creates a middleware, wraps into a list of one or more filters and executes it only, if all filters match all criteria (return a truely value).

    example
    import log, { consoleLogger, LoggerFilter, LogType, useFilter } from "@egomobile/log"

    const mySpecialFilter: LoggerFilter = (type, args) => {
    // return a truely value to indicate
    return type >= LogType.Debug &&
    process.env.NODE_ENV !== 'production'
    }

    log.reset()

    // use console logger only with
    // 'mySpecialFilter' instead
    log.use( useFilter(consoleLogger(), mySpecialFilter) )

    log('foo')

    Parameters

    Returns LoggerMiddleware

    The new middleware.

Generated using TypeDoc