0

I am using log4js-node for logs in application. Now what I want is to print the name of user logged in with the time stamp in logs. In java using log4j this could be done using MDC by exporting it and using as:

MDC.put("user",xyz);

How can this be done in nodejs with log4js.

Present:

[2014-06-16 17:24:14.593] [INFO] info - Express server listening on port %d in %s mode', port, app.get('env')

Desired:

[2014-06-16 17:24:14.593] [INFO] [admin] info - Express server listening on port %d in %s mode', port, app.get('env')

Any help would be appreciated. Thanks in advance.

James Jithin
  • 10,183
  • 5
  • 36
  • 51
Vaibhav Magon
  • 1,453
  • 1
  • 13
  • 29

2 Answers2

1

This could be done with some tweeks in the API of log4js. The timestamp is formatted in layout.js. There including the name of user from session might just solve the problem. thanks.

0

log4js has option to add tokens to the pattern. These tokens could be functions those return particular value.

Mentioned in the section Tokens of Layout configuration.

James Jithin
  • 10,183
  • 5
  • 36
  • 51