Winston 未在 node.js 中记录调试级别
Winston not logging debug levels in node.js
我不是 运行 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"}
好的,看来我误解了有关默认日志记录级别的文档。 As stated in this issue,我需要告诉winston它应该输出某些日志级别
import { Logger, format, createLogger, transports } from "winston";
export const exampleLogger = (): Logger => {
return createLogger({
transports: [new transports.Console({ level: 'debug' })],
format: format.combine(
format((info) => {
info.level = info.level.toUpperCase();
return info;
})(),
format.json(),
),
});
}
我不是 运行 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"}
好的,看来我误解了有关默认日志记录级别的文档。 As stated in this issue,我需要告诉winston它应该输出某些日志级别
import { Logger, format, createLogger, transports } from "winston";
export const exampleLogger = (): Logger => {
return createLogger({
transports: [new transports.Console({ level: 'debug' })],
format: format.combine(
format((info) => {
info.level = info.level.toUpperCase();
return info;
})(),
format.json(),
),
});
}