Winston: Stop winston logging with environment variable

Created on 28 Nov 2017  路  8Comments  路  Source: winstonjs/winston

Hi. I am using an npm dependency that logs with Winston. The logs are oppressive at times and make debugging other things a huge pain. Is there some environment variable I can set so that winston won't log at all? Can I change the log level in my env without going and editing my node_modules directory? That feature (if it doesn't exist already) would be very useful.

Most helpful comment

Using an env variable would allow suppression of winston's logging when its happening in a third party app. If i don't directly reference winston, i cant import it and silence it. An env variable really is the best and most intuitive solution IMO.

All 8 comments

Adding an ENV variable would be foggy and non-intuitive. Suggestion is to conditionally not add any transport according to that variable in your environment, so as should it be set no transport is set otherwise set to use the current ones (Console, File, Loggly, etc.)

I tried this but if you remove all transports Winston still logs to the console. Attempt to write logs with no transports. a bit frustrating, so I found the only way I could stop winston logging to the console was by making a noop custom logger. which is only added if NODE_ENV=test

any update in this? silent flag is not working as well.

@cassiopagnoncelli that's what the debug npm does. You set an env variable to see the debug output. I think it's more intuitive than having a dependency using winston polluting your logs with no way to turn it off.

The silent flag should be used for this purpose. It is however only implemented for Transport = File as of 3.0.0-rc1. I see the code in file.js:

  // Remark: (jcrugzz) What is necessary about this callback(null, true) now
  // when thinking about 3.x? Should silent be handled in the base
  // TransportStream _write method?
  //
  if (this.silent) {
    callback();
    return true;
  }

The same code is absent in console.js even though documentation says it should work. Either the docs should get fixed (easy "fix"), or the silent flag should be implemented for Transport = Console (actual fix).

Closing this in favor of #1245 -- the silent option will get added back for the base transport so all transports will be able to use it. Thanks for the feedback!

Using an env variable would allow suppression of winston's logging when its happening in a third party app. If i don't directly reference winston, i cant import it and silence it. An env variable really is the best and most intuitive solution IMO.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Infinitay picture Infinitay  路  3Comments

kjin picture kjin  路  3Comments

xungwoo picture xungwoo  路  3Comments

Tonacatecuhtli picture Tonacatecuhtli  路  4Comments

jlank picture jlank  路  4Comments