winstonjs/winston

Custom log levels can be silent unless level is also specified

开放

#1,491 创建于 2018年10月3日

 (6 条评论) (0 个反应) (0 位负责人)JavaScript (1,789 个派生)batch import
BugGood First IssueHelp Wanted

仓库指标

星标
 (21,967 个星标)
PR 合并指标
 (平均合并 68天 4小时) (30 天内合并 9 个 PR)

描述

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.

贡献者指南