@nanw/nwlog
v1.0.3
Published
New-wheel logger for NodeJs, just do it
Downloads
1
Readme
nwlog
A new-wheel logger for NodeJs. Simple do its task
- Short logging api: as it should be
- With log written to rotated file
- Decorate console ondemand, with colors
- Log file/module name, support custom label. (for cluster mode)
- NodeJs default console.log/util.format convension
- Tiny code
const log = require('@nanw/nwlog')(__filename)
//easy api
log('log')
//explicit level
log.debug('log.debug')
log.info('log.info')
log.warn('log.warn')
log.error('log.error')
//formatting
let d = {a: 1, b:'Transylvania'}
log('Formatting: %d %s %j', 12345, 'welcome to', d)
log('test error with stack:', new Error('demo'))
const log2 = require('@nanw/nwlog')('/anotherModule/index.js')
log2('Message from another module')
Options
const nwlog = require('@nanw/nwlog')
nwlog.config({
//decorateConsole: true, //whether decorate console.log/console.error. Default: true
//writeToConsole: true, //whether write to console for log operations. Default: true
//fileName: './log/console.log', //log file. If null, no log file will be created. Default: ./log/console.log
//maxLength: 4 * 1024 * 1024, //max file length
//maxFiles: 3, //max log files to keep
//custom: () => 'custom-label-' + process.pid, //A function to append custom label. E.g. add pid
//maskPassword: true //If enabled, tries to identify password string fields in log objects and mask them. Default: false
})
const log = nwlog(__filename)
log('log')