【发布时间】:2021-09-08 14:48:31
【问题描述】:
我没有在 VS Code 上运行它,只是一个普通的终端。
当我将具有不同级别的对象传递给 winston 时,它们都按预期输出 - 除了debug
import { Logger, format, createLogger, transports } from "winston";
export const exampleLogger = (): Logger => {
return createLogger({
transports: [new transports.Console()],
format: format.combine(
format((info) => {
info.level = info.level.toUpperCase();
return info;
})(),
format.json(),
),
});
}
import { exampleLogger } from './example'
const logger = exampleLogger();
const infoExample = {
timestamp: '2021-06-25T07:06:03.901Z',
level: 'info',
message: 'this works fine'
}
logger.log(infoExample)
const debugExample = {
timestamp: '2021-06-25T07:06:03.901Z',
level: 'debug',
message: 'this outputs nothing'
}
logger.log(debugExample)
const errorExample = {
timestamp: '2021-06-25T07:06:03.901Z',
level: 'error',
message: 'this works fine'
}
logger.log(errorExample)
执行
$ npx ts-node test.ts
{"timestamp":"2021-06-25T07:06:03.901Z","level":"INFO","message":"this works fine"}
{"timestamp":"2021-06-25T07:06:03.901Z","level":"ERROR","message":"this works fine"}
【问题讨论】:
标签: javascript node.js typescript logging winston