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

标签 javascript node.js winston

如何配置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/

相关文章:

javascript - Promise.all() - 拒绝 ID 2 - 未接收数据

javascript - MongoDB Node.js 按计算键分组

java - 使用 Java 的异步驱动程序时,并非所有文档都插入到 MongoDB 中

node.js - 在 Express.js 中使用 Winston 进行日志记录 - 如何针对不同的环境进行配置?

javascript - Github.com 之类的时间线图表

javascript - JavaScript 中的 IIFE 调用

php - 对php请求的post jquery请求使用一个删除函数

node.js - 如何正确使用 winston

json - 人类如何阅读 json winston 日志文件?

javascript - 在nodejs中理解V8的堆信息