winstonjs/winston

Custom log levels can be silent unless level is also specified

Offen

#1.491 geöffnet am 03.10.2018

 (6 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (1.789 Forks)batch import
BugGood First IssueHelp Wanted

Repository-Metriken

Stars
 (21.967 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

It is easy to write the following code and not realize that one has made a mistake:

const logger = winston.createLogger({
  levels: { eeny: 0, meeny: 1, miney: 2, moe: 3},
  transports: [
    new winston.transports.Console(),
  ]
});

logger.meeny('catch a tiger by the toe'); // never hollers

This could be addressed by the following check in the Logger constructor:

    if (!Object.keys(this.levels).includes(this.level)) {
      throw new Error(`Logger level ${this.level} is not in the levels: ${this.levels}`);
    }

I can open a PR if people agree it is worth fixing.

Contributor Guide