Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Dec 28, 2023 via pnpm

winston 3.8.0

A logger for just about everything.
Package summary
Share
0
issues
0
licenses
Package created
18 Jan 2011
Version published
23 Jun 2022
Maintainers
8
Total deps
0
Direct deps
0
License
MIT

Issues

0
This package has no issues

Frequently Asked Questions

What does winston do?

Winston is a versatile logging library for Node.js. It's designed to be simple, universal and with support for multiple transports. A transport in Winston is essentially a storage device for your logs. Each logger can have multiple transports configured at different levels. For example, one might want error logs to be stored in a persistent remote location (like a database), but all logs to output to the console or a local file. This offers a flexible and extensible logging solution that caters to a broad range of needs.

How do you use winston?

To use Winston in a JavaScript codebase, first, you need to install it via npm with npm install winston. After installation, create a logger using Winston's createLogger function. The function takes an object as a parameter, specifying the logging level, the format of the logs, and the transports.

For example:

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  defaultMeta: { service: 'user-service' },
  transports: [
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' }),
  ],
});

if (process.env.NODE_ENV !== 'production') {
  logger.add(new winston.transports.Console({
    format: winston.format.simple(),
  }));
}

In the example, we're setting the log level to 'info', which means only events at this level and above will be logged. Logs are formatted in JSON and will be written to two different files: error.log for error logs and combined.log for logs with lower than the error log level. When not in production mode, logs are also outputted to the console.

Where are the winston docs?

The documentation for Winston can be found at the official Github repository here. The comprehensive documentation includes information on core concepts, capabilities, various options and detailed code examples to guide you on using the library effectively for your logging needs. Make sure to explore the examples folder for practical usage examples of the library.