LogZen API Documentation

Note: Hidden from TypeDocs: Each of the logLevels (except NONE) corresponds to a method with the same name in lowercase (eg .warn() etc), along with .warn1() and .willWarn(). These methods are also bound to the instance, so you can also call as const warn = l.warn; warn('foo');`` instead of l.warn('foo')`.

For example

l.fatal(someVal, someOtherVal, ...)
l.fatal1(someVal, someOtherVal, ...)
l.willFatal()
...
l.info(someVal, someOtherVal, ...)
l.info1(someVal, someOtherVal, ...)
l.willInfo()

All of these are hidden from TypeDocs for brevity.

Accessors

  • get c(): typeof ansiColors
  • Returns typeof ansiColors

  • get c(): typeof ansiColors
  • Expose the whole ansi-colors package as "c", per its convention. Useful to have with you for logging!

    Returns typeof ansiColors

Constructors

  • Parameters

    • loggerName: string
    • OptionaldebugLevel: number

    Returns LogZen

  • Parameters

    • loggerName: string
    • OptionallogLevel:
          | "error"
          | "fatal"
          | "critical"
          | "notice"
          | "trace"
          | "warn"
          | "log"
          | "ok"
          | "info"
          | "verbose"
          | "debug"
          | "silly"
          | "NONE"
    • OptionaldebugLevel: number

    Returns LogZen

  • Parameters

    Returns LogZen

  • Parameters

    • Optionaloptions: OptionsAtConstructor
    • OptionallogLevel:
          | "error"
          | "fatal"
          | "critical"
          | "notice"
          | "trace"
          | "warn"
          | "log"
          | "ok"
          | "info"
          | "verbose"
          | "debug"
          | "silly"
          | "NONE"
    • OptionaldebugLevel: number

    Returns LogZen

Methods

  • Add a TLogPathOptions object, where:

    • Keys are paths in your project's filesystem (e.g. 'src/some/module'). They can be Replaced Paths or use shortcuts (see below).

    • Values are either:

      • an object of type LogZen Options eg {colors: true}

      • OR a number (even parsable string number), interpreted as debugLevel

      • OR a logLevel string eg 'warn', 'log' etc

    For example:

       {
    '/': {colors: false, logLevel: 'warn'} // obj as is - on root (CWD) of project, siting only before defaultOptions
    './some/path': 'info', // becomes {logLevel: 'info'}
    'some/other/buggy/path': '100', // becomes {debugLevel: 100}
    }

    with all your paths and corresponding options for each path.

    When calling multiple times, paths are updated (or added) with a custom _.merge over existing options. Thus, existing paths are not blindly overwritten, but their contents are merged (i.e. updated).

    The key in logPathOptions object, is some path in your project relative to CWD, for example:

    / # The root of your project, i.e the CWD

    src/domain/entities # a relative path to your CWD

      or
    

    MyLib@/some/path # refer by pathReplacement + extra path

     or
    

    node_modules/lib/dist/some/path # useful for foreign libraries

     or
    

    [~]/some/path which is a special shortcut for "current file I'm calling from". If [~] is in your path string, it is replaced with the filepath of the .js/.ts file you're calling it from (without the .js ext, & adjusted for CWD internally). For example [~]/some/path will be replaced with where/ever/youare/calling/from/some/path

    Parameters

    • logPathOptions: TLogPathOptions

      an object with {[logPath:string]: Options}

    • stackDepth: number = 0

      when calling from a nested file paths, but you want to capture the real file called from, use this to adjust the stack depth. Default is 0, i.e. the file calling LogZen.updateLogPathOptions()

    Returns typeof LogZen

    LogZen for fluent API

  • Add a TPathReplacements object, where:

    • keys are paths in your project's filesystem (e.g. 'src/some/project')

    • values are replacements (eg 'MyProject').

    For example:

      {
    'src/domain/entities': 'DomainEntities',
    'src/domain': 'Domain',
    '[~]/../..': 'Source',
    }

    See pathReplacements for more options & examples

    Parameters

    Returns typeof LogZen

    LogZen for fluent API

  • Inspect a value, using an extracted util.inspect(), default options and optional inspect options to override default options

    Parameters

    • value: any

      the value to inspect

    • inspectOptions: InspectOptions = defaultOptions

    Returns string

    the inspected value as a string

  • Clean the screen, if stdout is a TTY

    Returns typeof LogZen

    LogZen for fluent API

  • Start a timer on ALL instances, and next time you print with any l.xxx() log method onany instance, it displays how long it took (in the header).

    Parameters

    Returns number

    the timestamp when the timer was started (or null if always=false)

  • Returns number

    the difference since static LogZen.timer() was started, in milliseconds

  • Stops the current static timer, and returns the difference since static LogZen.timer() was started, in milliseconds (like .timerNow()).

    It restarts the timer if always was set to true in l.timer(true)

    Returns number

    the difference since static LogZen.timer() was started, in milliseconds

  • Resets all static logPathOptions & path Replacements to their default (empty) values.

    Forces recalculation of effective options on all instances (on demand)

    Returns typeof LogZen

    LogZen for fluent API

  • The options() method, either gets current effective options OR it updates the options of the instance (and returns it).

    • Pass no argument (in this variant), and you get current effective options (of instance) eg {colors: true, logLevel: 'warn'}.
    • Pass newOptions to update existing instance options, causing revaluation of effective options. It returns this, i.e the logger instance, so you can do fluently do l.options({colors: false}).log('Hello boring world')

    Returns Readonly<Options>

    Options current effective options

  • The options() method, either gets current effective options OR it updates the options of the instance (and returns it).

    • Pass newOptions (in this variant) to update existing instance options, causing revaluation of effective options. It returns this, i.e the logger instance, so you can do fluently do l.options({colors: false}).log('Hello boring world')
    • Pass no arguments, get current effective options (of instance) eg {colors: true, logLevel: 'warn'}.

    Parameters

    Returns LogZen

    LogZen instance

  • Inspect a value, using an extracted util.inspect(), instance options and optional inspect options to override instance options

    Parameters

    • value: any

      the value to inspect

    • inspectOptions: InspectOptions = ...

    Returns string

    the inspected value as a string

  • Start a timer on specific instance, and next time you print l.xxx() with any log method on specific instance, it displays how long it took (in the header).

    Parameters

    Returns any

    the timestamp when the timer was started (or null if always=false)

  • Returns the difference since .timer() was started, in milliseconds (like .timerNow()).

    Returns any

    the difference since .timer() was started, in milliseconds

  • Stops the current instance timer, and returns the difference since .timer() was started, in milliseconds (like .timerNow()).

    It restarts the timer if always was set to true in l.timer(true)

    Returns any

    the difference since .timer() was started, in milliseconds

  • For a given path of a runtime log(), for example ['src', 'entities', 'customer'], it retrieves all Options from PATHS_OPTIONS_KEY starting from deepest kid, up to the top of the hierarchy to the root (ie ['zen', 'objects'], then ['zen'] & ['']

    It reads them from LogZen._logPathOptions that holds these static (i.e global LogZen) options.

    Parameters

    • Optionalpath: string | string[]

      the path to collect options for. Default is empty array, which means root options

    Returns OptionsInternal[]

    options objects in reverse collected order (root on top, last path at bottom), ready for blending (i.e Object.assign etc ;-)

  • Protected

    Gets the output object, either from options.output, or from builtInOutputs if it is a string.

    Returns Output

  • The actual log method, that all other log methods call.

    Parameters

    • logTitle:
          | "error"
          | "fatal"
          | "critical"
          | "notice"
          | "trace"
          | "warn"
          | "log"
          | "ok"
          | "info"
          | "verbose"
          | "debug"
          | "silly"
          | "table"
          | "dir"
          | "NONE"
    • logLevel: ELogLevel
    • color: StyleFunction
    • argsToLog: any[]

    Returns any[]

  • Type Parameters

    • TLastArg

    Parameters

    • logMethodName:
          | "error"
          | "fatal"
          | "critical"
          | "notice"
          | "trace"
          | "warn"
          | "log"
          | "ok"
          | "info"
          | "verbose"
          | "debug"
          | "silly"
          | "table"
          | "dir"
          | "NONE"
    • logLevel: ELogLevel
    • argsToPrint: TLog1MethodArgsToReturnLastArg<TLastArg>

    Returns TLastArg

  • Protected

    The actual log method for leveled log (i.e debug & trace), that all other log methods call.

    Parameters

    Returns boolean | any[]

Properties

table: TlogMethod = ...

Prints using console.table() with some enhancements and caveats

the args passed to console.table(), with the table data & header appended

table1: Tlog1Method = ...

Prints using console.table() with some enhancements and caveats, returning the lastArg (which is also what is passed to console.table())

the args to print, with the last arg being the one to return

lastArg passed (i.e the tabularData or tableHeader)

dir: TlogMethod = ...

Prints using console.dir() if console output is used, but its not part of logLevel methods

It has a fixed ELogLevel.log severity.

the args passed

dir1: Tlog1Method = ...

Prints using console.dir() if console output is used, but it's not part of logLevel methods

It has a fixed ELogLevel.log severity.

the last arg passed

_instanceCount: number
_pathReplacements: TPathReplacements = {}
_resolvePathsAndNames: ((__namedParameters: {
    fullPathToResolve: string;
    pathReplacements: TPathReplacements;
    cwd: string;
}) => {
    resolvedName: string;
    replacedPath: string;
    relativePath: string;
    distanceFromReplacedPath: string;
    matchedPath: string;
}) = resolvePathsAndNames
_blendOptions: ((__namedParameters: {
    options: Options[];
    isForLogPathOptions?: boolean;
}) => OptionsInternal) = blendOptions
_logPathOptions: {} = {}
_optionsVersion: number = 1
_timerStart: number
_timerAlways: boolean
_CWD: string
_absolutePath: string
_relativePath: string
_optionsVersion: number
_resolvedName: string
_loggerId: number = -1
_realConstructArgs: [options?: OptionsAtConstructor, logLevel?:
    | "error"
    | "fatal"
    | "critical"
    | "notice"
    | "trace"
    | "warn"
    | "log"
    | "ok"
    | "info"
    | "verbose"
    | "debug"
    | "silly"
    | "NONE", debugLevel?: number]
_instanceOptions: OptionsAtConstructor
_effectiveOutput: Output
_kidsFromOptions: LogZen[] = []
_kidFromOptionsCounter: number = 0
_kidFromOptionsId: number = null
_parent: LogZen
_kids: LogZen[] = []
_kidCounter: number = 0
_kidId: any = null
_timerStart: number
_timerAlways: boolean
_leveledLogInfo: {
    [logLevel: string]: {
        lastIsLevelCheck: number;
        leveledCheckPrevious: number;
    };
} = {}
_debugLog: TlogMethod = ...
_traceLog: TlogMethod = ...