Category: 08. Winston
-
Querying Logs
If you’re logging to a database or an external service, querying logs can be useful. For instance, with MongoDB and winston-mongodb, you can query logs like this:
-
Log Rotation
For managing log file sizes and rotation, you can use the winston-daily-rotate-file transport. Install it first: Then configure it like so:
-
Custom Transports
Winston supports creating custom transports to log messages in unique ways. Here’s a basic example of a custom transport:
-
Multiple Transports
You can send logs to multiple destinations. For example, you might want to log errors to a file and info messages to the console.
-
Customizing Formats
Winston provides several formats to structure your logs. You can also create custom formats. This example combines a timestamp and JSON format.
-
Log Levels
Winston uses different log levels. By default, they are: You can configure the level of logging you want. For example, if you only want to log info and above, you set the level to info.