Node.js日志之winston

208次阅读
没有评论
level 'info' Log only if info.level is less than or equal to this level
levels winston.config.npm.levels Levels (and colors) representing log priorities
format winston.format.json Formatting for info messages (see: Formats)
transports [] (No transports) Set of logging targets for info messages
exitOnError true If false, handled exceptions will not cause process.exit
silent false If true, all logs are suppressed
const levels = {
  error: 0,
  warn: 1,
  info: 2,
  http: 3,
  verbose: 4,
  debug: 5,
  silly: 6
};

如果logger的level是warn,下面的代码中只有 warn和error生效。

const logger = winston.createLogger({
  level: 'warn',
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({ filename: 'combined.log' })
  ]
});
logger.error('error message')
logger.warn('warn message')
logger.info('info message')

控制台输出的和’combined.log文件存储的都只有:

{"level":"error","message":"error message"}
{"level":"warn","message":"warn message"}
正文完
 0
wujingquan
版权声明:本站原创文章,由 wujingquan 于2024-07-05发表,共计814字。
转载说明:Unless otherwise specified, all articles are published by cc-4.0 protocol. Please indicate the source of reprint.
评论(没有评论)