Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

In my Node.js applications, I often find it helpful to have an application log so that should something go wrong in production, I can have more information than I get from a crash stack trace to track down problems.

To facilitate this, I use a global instance of Winston which is set up as one of the first things in my code:

var winston = require('winston');

global.applog = new (winston.Logger)({
  transports: [
    new (winston.transports.Console)({
      timestamp: true,
      level: 'debug'
    })
  ]
});

I then call applog.debug(), applog.info(), applog.warn(), and applog.error() as appropriate throughout my code. Even if I am in a class included from the main application, I will often send debug messages.

For my purposes, this works great. I get the information I need to keep things running smoothly, and handle unexpected behaviors. However:

  • This reduces the reuse of any lib code as it cannot stand on its own without having a reference to applog.
  • It doesn't feel like a best practice to have global references used inside modular object-oriented code.
  • I don't think I would ever use a log utility that didn't have the standard methods (debug, info, warn, error), but if I did switch away from Winston it's possible that all my code would need to be updated.

Is there a more appropriate pattern I should be following for logging?

share|improve this question

1 Answer 1

i hope that this module xlblogger could help:

logger.stopLog();

Stop logging: The goal of the "Stop" instruction is to provide the option of disabling the logger without commenting or deleting our messages.

share|improve this answer
4  
I don't see how this addresses any of the concerns of the question –  janos Jul 6 at 13:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.