winstonjs/winston

Best way to get highest log level

Open

#837 aperta il 24 mar 2016

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)JavaScript (1789 fork)batch import
Feature RequestGood First IssueHelp Wanted

Metriche repository

Star
 (21.967 star)
Metriche merge PR
 (Merge medio 68g 4h) (9 PR mergiate in 30 g)

Descrizione

I have a logger where if one of the transports is at 'debug' or higher, it logs a lot more information than would normally be needed. Some of this data requires other processing before it can be logged. So, before logging, I check the highest log level to see if that extra work really needs to be done.

I've been using the following to find the highest log level on a given logger:

winston.Logger.prototype.getHighestLogLevel = function() {
  var result = 0;

  for(var i in logger.transports) {
    result = Math.max(result, logger.levels[logger.transports[i].level || logger.level]);
  }

  return result;
}

Is there a simplified way to do this? If not, would there be a problem with merging this?

Guida contributor