[英]node.js winston logging module - how to put timestamp at start of line instead of end
[英]Winston : How to get logging with timestamp at the front
如何配置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()
)
});
錯誤:奶酪爛了! {“ timestamp”:“ 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()]
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.