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.
winston is designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device for your logs. Each winston logger can have multiple transports (see: Transports) configured at different levels (see: Logging levels).
Winston is the most popular logging library for Node. js. It aims to make logging more flexible and extensible by decoupling different aspects such as log levels, formatting, and storage so that each API is independent and many combinations are supported. It also uses Node.
Creating the Custom Logger classcreateLogger() method. If you wish to completely change the format of the logs you could refer to Winston docs.
In winston a transport is essentially a storage device for your logs. Each instance of a winston logger can have multiple transports configured at different levels. For example, one may want error logs to be stored in a persistent remote location (like a database), but all logs output to the console or a local file.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With