Skip to content

Latest commit

 

History

History
163 lines (112 loc) · 3.79 KB

LogLevel.md

File metadata and controls

163 lines (112 loc) · 3.79 KB

LogLevel

Every instance of a log in loglevelnext is a LogLevel class. This reference applies both to the default logger and all loggers created with getLogger().

Log Levels

By default loglevelnext ships supporting the following log level name-value pairs:

{
  TRACE: 0,
  DEBUG: 1,
  INFO: 2,
  WARN: 3,
  ERROR: 4,
  SILENT: 5
}

Methods

constructor(options)

The constructor for this class accepts an options Object. The following is a property reference for the Object:

factory

Type: Class:MethodFactory Default: null

Specifies the factory to use when wrapping console methods. The value must be a class which inherits from MethodFactory.

level

Type: String Default: 'info'

Specifies the level the logger should use. A logger will not produce output for any log level beneath the specified level. Available levels and order are:

[
  'trace',
  'debug',
  'info',
  'warn',
  'error',
  'silent'
]

Note: The level names shown above correspond to the available logging methods, with the notable exception of the silent level.

name

Type: String Default: +new Date()

Specifies the name of the log to create. This property is required, and used to differentiate between loggers when webpack-log is used in multiple projects executing in the same process space.

prefix

The prefix object defines properties for adding a prefix to each bit of data logged.

disable() { this.level = this.levels.SILENT; }

disable

Instructs the logger to hide output for every log level. This is equivalent to setting the level property to 'silent' or 5.

enable

Instructs the logger to produce output for every log level. This is equivalent to setting the level property to 'trace' or 0.

Properties

level(options)

Type: Function Default: options => `[${options.level}]`

A function used to define the value used to replace instances of {{level}} within the prefix template. The options argument will contain an Object matching { level: (String), logger: (LogLeveL) }. This function should represent the current level of log producing output.

name(options)

Type: Function Default: options => `[${options.name}]`

A function used to define the value used to replace instances of {{name}} within the prefix template. The options argument will contain an Object matching { level: (String), logger: (LogLeveL) }. This function should represent the name of the logger producing output.

template

Type: String Default: '{{time}} {{level}} '

Defines the template that represents the prefix. The template uses Mustache syntax. When prefixing log output, the logger will interpolate the template string and attempt to execute a function on the prefix object corresponding to a given tag.

For example:

{
  prefix: {
    foo: () => 'bar',
    template: '{{foo}}-'
  }
}

Would then result in a prefix of 'bar-' prepended to the output for each log method call.

time()

Type: Function Default: () => new Date().toTimeString().split(' ')[0]

A function used to define the value used to replace instances of {{time}} within the prefix template. This function should represent the time at which the logger produced output.

Properties

factory

Type: Class:MethodFactory

Gets or sets the factory to use when wrapping console methods. When setting this property, the value must be a class which inherits from MethodFactory.

level

Type: String|Number

Gets or sets the level the log should operate on. When setting this property, the value must be a String or Number.

levels

Type: Object

Gets an object which represents the valid level name-value pairs for this log instance.