本文介绍了温斯顿记录器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flatiron的日志库Winston非常有用,但我无法想象如何为记录器分配名称。我希望输出类似于其他日志库,例如:

Flatiron's logging library Winston is quite useful, but I can not figure how to assign names to loggers. I am expecting an output similar to other logging libraries, for instance:

 [<date>] [<log level>] <logger name> - <the message>

是否可以这样配置Winston?

Is it possible to configure Winston in such a way?

谢谢。

推荐答案

创建日志传输时,您可以提供标签将添加到日志级别和日志消息之间的日志输出的参数。例如:

When creating a logging transport, you can provide a label parameter which will be added to the log output between the log level and the log message. For example:

var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.Console)({
            colorize: true,
            prettyPrint: true,
            timestamp: true,
            label: 'CustomLabel'
        })
    ]
});

这将产生以下输出:

2016-09-06T12:16:17.335Z - info: [CustomLabel] hello

这篇关于温斯顿记录器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:35