Winston logger names

2019-06-19 08:05发布

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>

Is it possible to configure Winston in such a way?

Thank you.

3条回答
ら.Afraid
2楼-- · 2019-06-19 08:34

https://github.com/mcclellanmj/SimplyLog goes on the premise of being able to code your own appenders with custom output easily and is centered around named loggers.

查看更多
不美不萌又怎样
3楼-- · 2019-06-19 08:35

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'
        })
    ]
});

This will result in the following output:

2016-09-06T12:16:17.335Z - info: [CustomLabel] hello
查看更多
混吃等死
4楼-- · 2019-06-19 08:40

You can name loggers; however, there doesn't appear to be a way to add the logger name to the output.

But I would use this too, if it was available. There is an open pull request that would allow this by adding a 'name' to the output string, so hopefully that comes through.

查看更多
登录 后发表回答