winston-like-debug
v1.3.1
Published
Format logs with Winston like you do with Debug
Downloads
3,684
Maintainers
Readme
winston-like-debug
Format logs with Winston like you do with Debug
const log = require('./logger')('my.controller')
log.info('hi', { from: 'foo' })
log.verbose({ some: 'test' })
log.warn('Invalid userid')
log.silly('Hi %s', 'Bob', { greetings: true }, { when: Date.now() })
log.error('Error reading file')
log.debug('config', { my: 'var' })
Install
yarn add winston-like-debug
npm install winston-like-debug
Usage
logger.js
const winston = require('winston')
const { likeDebug, withNamespace } = require('winston-like-debug')
const logger = winston.createLogger({
// This is required to be at top level format
// See https://github.com/winstonjs/winston/issues/1430
format: winston.format.splat(),
})
logger.add(
new winston.transports.Console({
level: 'silly',
format: likeDebug(),
})
)
logger.add(
new winston.transports.File({
level: 'debug',
filename: __dirname + '/output.log',
format: likeDebug({ colors: false }),
})
)
module.exports = withNamespace(logger)
Using namespaced logger
index.js
const log = require('./logger')('root')
log.verbose('listening', { host: 'localhost' }, { port: 3000 })
Console output:
output.log file content:
2010-01-30T10:04:43.824Z VERBOSE root listening {"host":"localhost","port":3000}
Namespace based on filename
auth.controller.js
const log = require('./logger')(module)
log.warn('login', { userId: 98356190 })
Console output:
output.log file content:
2010-01-30T10:08:03.386Z WARN auth.controller login {"userId":98356190}