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"}
正文完