@winkgroup/console-log
v3.0.3
Published
Enhanced logging class
Downloads
9
Keywords
Readme
console-log
enhanced logging library
Install
npm install @winkgroup/console-log
Usage
import ConsoleLog from '@winkgroup/console-log'
consoleLog = new ConsoleLog()
consoleLog.print('hello world!')
you can set prefix
and id
properties that will become part of header of each log:
import ConsoleLog from '@winkgroup/console-log'
consoleLog = new ConsoleLog({prefix: 'CoolLog', id: '1'})
consoleLog.print('hello world!')
// will print: CoolLog (1): hello world!
API
ConsoleLog(GeneralOptions, SpecificOptions)
GeneralOptions
and SpecificOptions
are two optional objects.
methods:
ConsoleLog.print(message, [logLevel])
:message
is a string;logLevel
is a value from LogLevelConsoleLog.debug(message)
: shortcut ofprint
method with DEBUG LogLevelConsoleLog.warn(message)
: shortcut ofprint
method with WARN LogLevelConsoleLog.error(message)
: shortcut ofprint
method with ERROR LogLevelConsoleLog.spawn(GeneralOptions)
: it generates a newConsoleLog
object that inherits same options of original with some updates according with parameters passed
GeneralOptions
all the attributes of this object are optional:
- GeneralOptions.id: an id that will be shown for each log
- GeneralOptions.prefix: a prefix that will be shown for each log
- GeneralOptions.timestampFormat: a timestamp with these possible values: 'full', 'time', 'milliseconds', 'none' (default)
- GeneralOptions.verbosity: every log that is below this LogLevel will have no action
SpecificOptions
all the attributes of this object are optional, all those not declared will be inherited by GeneralOptions:
- SpecificOptions.id: an id that will be shown for each log
- SpecificOptions.prefix: a prefix that will be shown for each log
- SpecificOptions.timestampFormat: a timestamp with these possible values: 'full', 'time', 'milliseconds', 'none' (default)
- SpecificOptions.levels: LogLevel to those this option has to be applied, single level can be expressed. If this attribute is not set, then these options will be applied to any LogLevel
- SpecificOptions.action: object containing one of these actions: 'console' | 'file' | 'error' | 'none'
LogLevel
ConsoleLog comes with five verbosity levels:
- DEBUG = 4
- INFO = 3
- WARN = 2
- ERROR = 1
- NONE = 0
Tips
chalk v5 does't work properly in commonjs. To upgrade to minor version with ncu the command is
ncu -u -t minor