簡體   English   中英

Winston:如何在最前面使用時間戳記日志

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM