Friday, 17 March 2017

Add module name in winston log entries

Is there a possibility to save the current module name in order to be printed automatically in winston log entries when they are called later?

Currently, when I want to print the module name in logs, I have to add it manually:

var logHeader = 'mymodule'

log.info(logHeader + 'Hello')

For example, with debug, you can do (ignore the log format feature %s for now):

var debug = require('debug')('http')
  , name = 'My App'

debug('booting %s', name);

This will prin http prefix before the log:

http booting My App

Can this be done in winston? I have searched in the documentation but I couldn't find anything relevant.



via Alexandru Irimiea

No comments:

Post a Comment