@nanw/nwlog

1.0.3 • Public • Published

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')

nwlog screenshot

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')

Readme

Keywords

Package Sidebar

Install

npm i @nanw/nwlog

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

12.4 kB

Total Files

9

Last publish

Collaborators

  • nanw