gpt4 book ai didi

javascript - winston : How to get logging with timestamp at the front

转载 作者:行者123 更新时间:2023-12-02 23:23:49 26 4
gpt4 key购买 nike

如何配置Winston输出日志

2019-06-30 17:39:07:错误:奶酪已经腐烂

我尝试了这个,但它在末尾输出时间戳

const logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp({format: 'YYYY-MM-DD HH:mm:ss'}),
winston.format.simple()
)
});

错误:奶酪已经腐烂! {“时间戳”:“2019-06-30 23:32:02”}

最佳答案

尝试下面的代码。我希望这能解决这个问题。您可以在myFormat自定义函数中按照自己需要的方式进行自定义

const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} : [${label}] : ${level}: ${message}`;
});

const logger = createLogger({
format: combine(
label({ label: 'right meow!' }),
timestamp(),
myFormat
),
transports: [new transports.Console()]
});

关于javascript - winston : How to get logging with timestamp at the front,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56826988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com