logger
Configurable console logger with support for multiple independent groups.

Install
npm i @haxtra/logger
Usage
Basic
const Logger = require('@haxtra/logger')
const log = Logger()
log.info('Hello world!')
Multiple loggers
const apilog = Logger('api')
const apilog = log.spawn('api')
Set name and level at creation time
Logger('api', 'warning')
Logger({group:'api', level:'warning'})
log.spawn('api', 'warning')
log.spawn({group:'api', level:'warning'})
Log arbitrary objects
log.info('Mysterious object', {foo:'bar'})
Config
Global
Configure global settings
Logger.config({
level: 'trace',
group: true,
timestamp: true,
milli: true,
color: true,
icons: false,
})
Global settings can also be changed via logger instance
log.setGlobalConfig(object)
Instance
Set level
log.setLevel(level)
Set global level
log.setGlobalLevel(level)
Change group name
log.setGroup(groupName)
Log Levels
By default, instances have a level of null, and they follow the global setting. But you can, for example, set error as the global level and then trace for a particular instance to get a detailed log from just that one particular module.
log.trace
log.debug
log.dev
log.success
log.ok
log.info
log.notice
log.warning
log.alert
log.error
log.exception
log.critical
log.fatal
Set levels by:
log.setLevel(level)
log.setGlobalLevel(level)
Pausing output
Logging can be paused anytime by:
log.pause()
log.resume()
log.pauseGlobal()
log.resumeGlobal()
Remove logger
Delete logger instance by:
log.dispose()
Haxxor Tricks
Access underlying state via these objects:
log.$
log.localConfig
log.globalConfig
File logging
Currently logger does not support file logging, but you can redirect stdout and stderr to a file, by using the commands below. Note: you might want to disable color output, or strip ansi control codes on the fly with tools like ansi2txt or sed.
# log stdout and stderr to one file
node app.js >> app.log 2>&1
# log stdout and stderr to separate files
node app.js >> stdout.log 2>> stderr.log
License
MIT
