Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

winston

winstonjs40.5mMIT3.17.0TypeScript support: included

A logger for just about everything.

winston, logger, logging, logs, sysadmin, bunyan, pino, loglevel, tools, json, stream

readme

winston

A logger for just about everything.

Version npm npm Downloads build status coverage status

NPM

winston@3

See the Upgrade Guide for more information. Bug reports and PRs welcome!

Looking for `winston@2.x` documentation?

Please note that the documentation below is for winston@3. Read the winston@2.x documentation.

Motivation

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). 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.

winston aims to decouple parts of the logging process to make it more flexible and extensible. Attention is given to supporting flexibility in log formatting (see: Formats) & levels (see: Using custom logging levels), and ensuring those APIs decoupled from the implementation of transport logging (i.e. how the logs are stored / indexed, see: Adding Custom Transports) to the API that they exposed to the programmer.

Quick Start

TL;DR? Check out the quick start example in ./examples/. There are a number of other examples in ./examples/*.js. Don't see an example you think should be there? Submit a pull request to add it!

Usage

The recommended way to use winston is to create your own logger. The simplest way to do this is using winston.createLogger:

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  defaultMeta: { service: 'user-service' },
  transports: [
    //
    // - Write all logs with importance level of `error` or higher to `error.log`
    //   (i.e., error, fatal, but not other levels)
    //
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    //
    // - Write all logs with importance level of `info` or higher to `combined.log`
    //   (i.e., fatal, error, warn, and info, but not trace)
    //
    new winston.transports.File({ filename: 'combined.log' }),
  ],
});

//
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
//
if (process.env.NODE_ENV !== 'production') {
  logger.add(new winston.transports.Console({
    format: winston.format.simple(),
  }));
}

You may also log directly via the default logger exposed by require('winston'), but this merely intended to be a convenient shared logger to use throughout your application if you so choose. Note that the default logger doesn't have any transports by default. You need add transports by yourself, and leaving the default logger without any transports may produce a high memory usage issue.

Table of contents

Logging

Logging levels in winston conform to the severity ordering specified by RFC5424: severity of all levels is assumed to be numerically ascending from most important to least important.

const levels = {
  error: 0,
  warn: 1,
  info: 2,
  http: 3,
  verbose: 4,
  debug: 5,
  silly: 6
};

Creating your own Logger

You get started by creating a logger using winston.createLogger:

const logger = winston.createLogger({
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({ filename: 'combined.log' })
  ]
});

A logger accepts the following parameters:

Name Default Description
level 'info' Log only if info.level is less than or equal to this level
levels winston.config.npm.levels Levels (and colors) representing log priorities
format winston.format.json Formatting for info messages (see: Formats)
transports [] (No transports) Set of logging targets for info messages
exitOnError true If false, handled exceptions will not cause process.exit
silent false If true, all logs are suppressed

The levels provided to createLogger will be defined as convenience methods on the logger returned.

//
// Logging
//
logger.log({
  level: 'info',
  message: 'Hello distributed log files!'
});

logger.info('Hello again distributed logs');

You can add or remove transports from the logger once it has been provided to you from winston.createLogger:

const files = new winston.transports.File({ filename: 'combined.log' });
const console = new winston.transports.Console();

logger
  .clear()          // Remove all transports
  .add(console)     // Add console transport
  .add(files)       // Add file transport
  .remove(console); // Remove console transport

You can also wholesale reconfigure a winston.Logger instance using the configure method:

const logger = winston.createLogger({
  level: 'info',
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({ filename: 'combined.log' })
  ]
});

//
// Replaces the previous transports with those in the
// new configuration wholesale.
//
const DailyRotateFile = require('winston-daily-rotate-file');
logger.configure({
  level: 'verbose',
  transports: [
    new DailyRotateFile(opts)
  ]
});

Creating child loggers

You can create child loggers from existing loggers to pass metadata overrides:

const logger = winston.createLogger({
  transports: [
    new winston.transports.Console(),
  ]
});

const childLogger = logger.child({ requestId: '451' });

.child is likely to be bugged if you're also extending the Logger class, due to some implementation details that make this keyword to point to unexpected things. Use with caution.

Streams, objectMode, and info objects

In winston, both Logger and Transport instances are treated as objectMode streams that accept an info object.

The info parameter provided to a given format represents a single log message. The object itself is mutable. Every info must have at least the level and message properties:

const info = {
  level: 'info',                 // Level of the logging message
  message: 'Hey! Log something?' // Descriptive message being logged.
};

Properties besides level and message are considered as "meta". i.e.:

const { level, message, ...meta } = info;

Several of the formats in logform itself add additional properties:

Property Format added by Description
splat splat() String interpolation splat for %d %s-style messages.
timestamp timestamp() timestamp the message was received.
label label() Custom label associated with each message.
ms ms() Number of milliseconds since the previous log message.

As a consumer you may add whatever properties you wish – internal state is maintained by Symbol properties:

  • Symbol.for('level') (READ-ONLY): equal to level property. Is treated as immutable by all code.
  • Symbol.for('message'): complete string message set by "finalizing formats":
    • json
    • logstash
    • printf
    • prettyPrint
    • simple
  • Symbol.for('splat'): additional string interpolation arguments. Used exclusively by splat() format.

These Symbols are stored in another package: triple-beam so that all consumers of logform can have the same Symbol reference. i.e.:

const { LEVEL, MESSAGE, SPLAT } = require('triple-beam');

console.log(LEVEL === Symbol.for('level'));
// true

console.log(MESSAGE === Symbol.for('message'));
// true

console.log(SPLAT === Symbol.for('splat'));
// true

NOTE: any { message } property in a meta object provided will automatically be concatenated to any msg already provided: For example the below will concatenate 'world' onto 'hello':

logger.log('error', 'hello', { message: 'world' });
logger.info('hello', { message: 'world' });

Formats

Formats in winston can be accessed from winston.format. They are implemented in logform, a separate module from winston. This allows flexibility when writing your own transports in case you wish to include a default format with your transport.

In modern versions of node template strings are very performant and are the recommended way for doing most end-user formatting. If you want to bespoke format your logs, winston.format.printf is for you:

const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;

const myFormat = printf(({ level, message, label, timestamp }) => {
  return `${timestamp} [${label}] ${level}: ${message}`;
});

const logger = createLogger({
  format: combine(
    label({ label: 'right meow!' }),
    timestamp(),
    myFormat
  ),
  transports: [new transports.Console()]
});

To see what built-in formats are available and learn more about creating your own custom logging formats, see logform.

Combining formats

Any number of formats may be combined into a single format using format.combine. Since format.combine takes no opts, as a convenience it returns pre-created instance of the combined format.

const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, prettyPrint } = format;

const logger = createLogger({
  format: combine(
    label({ label: 'right meow!' }),
    timestamp(),
    prettyPrint()
  ),
  transports: [new transports.Console()]
})

logger.log({
  level: 'info',
  message: 'What time is the testing at?'
});
// Outputs:
// { level: 'info',
//   message: 'What time is the testing at?',
//   label: 'right meow!',
//   timestamp: '2017-09-30T03:57:26.875Z' }

String interpolation

The log method provides the string interpolation using util.format. It must be enabled using format.splat().

Below is an example that defines a format with string interpolation of messages using format.splat and then serializes the entire info message using format.simple.

const { createLogger, format, transports } = require('winston');
const logger = createLogger({
  format: format.combine(
    format.splat(),
    format.simple()
  ),
  transports: [new transports.Console()]
});

// info: test message my string {}
logger.log('info', 'test message %s', 'my string');

// info: test message 123 {}
logger.log('info', 'test message %d', 123);

// info: test message first second {number: 123}
logger.log('info', 'test message %s, %s', 'first', 'second', { number: 123 });

Filtering info Objects

If you wish to filter out a given info Object completely when logging then simply return a falsey value.

const { createLogger, format, transports } = require('winston');

// Ignore log messages if they have { private: true }
const ignorePrivate = format((info, opts) => {
  if (info.private) { return false; }
  return info;
});

const logger = createLogger({
  format: format.combine(
    ignorePrivate(),
    format.json()
  ),
  transports: [new transports.Console()]
});

// Outputs: {"level":"error","message":"Public error to share"}
logger.log({
  level: 'error',
  message: 'Public error to share'
});

// Messages with { private: true } will not be written when logged.
logger.log({
  private: true,
  level: 'error',
  message: 'This is super secret - hide it.'
});

Use of format.combine will respect any falsey values return and stop evaluation of later formats in the series. For example:

const { format } = require('winston');
const { combine, timestamp, label } = format;

const willNeverThrow = format.combine(
  format(info => { return false })(), // Ignores everything
  format(info => { throw new Error('Never reached') })()
);

Creating custom formats

Formats are prototypal objects (i.e. class instances) that define a single method: transform(info, opts) and return the mutated info:

  • info: an object representing the log message.
  • opts: setting specific to the current instance of the format.

They are expected to return one of two things:

  • An info Object representing the modified info argument. Object references need not be preserved if immutability is preferred. All current built-in formats consider info mutable, but [immutablejs] is being considered for future releases.
  • A falsey value indicating that the info argument should be ignored by the caller. (See: Filtering info Objects) below.

winston.format is designed to be as simple as possible. To define a new format, simply pass it a transform(info, opts) function to get a new Format.

The named Format returned can be used to create as many copies of the given Format as desired:

const { format } = require('winston');

const volume = format((info, opts) => {
  if (opts.yell) {
    info.message = info.message.toUpperCase();
  } else if (opts.whisper) {
    info.message = info.message.toLowerCase();
  }

  return info;
});

// `volume` is now a function that returns instances of the format.
const scream = volume({ yell: true });
console.dir(scream.transform({
  level: 'info',
  message: `sorry for making you YELL in your head!`
}, scream.options));
// {
//   level: 'info'
//   message: 'SORRY FOR MAKING YOU YELL IN YOUR HEAD!'
// }

// `volume` can be used multiple times to create different formats.
const whisper = volume({ whisper: true });
console.dir(whisper.transform({
  level: 'info',
  message: `WHY ARE THEY MAKING US YELL SO MUCH!`
}, whisper.options));
// {
//   level: 'info'
//   message: 'why are they making us yell so much!'
// }

Logging Levels

Logging levels in winston conform to the severity ordering specified by RFC5424: severity of all levels is assumed to be numerically ascending from most important to least important.

Each level is given a specific integer priority. The higher the priority the more important the message is considered to be, and the lower the corresponding integer priority. For example, as specified exactly in RFC5424 the syslog levels are prioritized from 0 to 7 (highest to lowest).

{
  emerg: 0,
  alert: 1,
  crit: 2,
  error: 3,
  warning: 4,
  notice: 5,
  info: 6,
  debug: 7
}

Similarly, npm logging levels are prioritized from 0 to 6 (highest to lowest):

{
  error: 0,
  warn: 1,
  info: 2,
  http: 3,
  verbose: 4,
  debug: 5,
  silly: 6
}

If you do not explicitly define the levels that winston should use, the npm levels above will be used.

Using Logging Levels

Setting the level for your logging message can be accomplished in one of two ways. You can pass a string representing the logging level to the log() method or use the level specified methods defined on every winston Logger.

//
// Any logger instance
//
logger.log('silly', "127.0.0.1 - there's no place like home");
logger.log('debug', "127.0.0.1 - there's no place like home");
logger.log('verbose', "127.0.0.1 - there's no place like home");
logger.log('info', "127.0.0.1 - there's no place like home");
logger.log('warn', "127.0.0.1 - there's no place like home");
logger.log('error', "127.0.0.1 - there's no place like home");
logger.info("127.0.0.1 - there's no place like home");
logger.warn("127.0.0.1 - there's no place like home");
logger.error("127.0.0.1 - there's no place like home");

//
// Default logger
//
winston.log('info', "127.0.0.1 - there's no place like home");
winston.info("127.0.0.1 - there's no place like home");

winston allows you to define a level property on each transport which specifies the maximum level of messages that a transport should log. For example, using the syslog levels you could log only error messages to the console and everything info and below to a file (which includes error messages):

const logger = winston.createLogger({
  levels: winston.config.syslog.levels,
  transports: [
    new winston.transports.Console({ level: 'error' }),
    new winston.transports.File({
      filename: 'combined.log',
      level: 'info'
    })
  ]
});

You may also dynamically change the log level of a transport:

const transports = {
  console: new winston.transports.Console({ level: 'warn' }),
  file: new winston.transports.File({ filename: 'combined.log', level: 'error' })
};

const logger = winston.createLogger({
  transports: [
    transports.console,
    transports.file
  ]
});

logger.info('Will not be logged in either transport!');
transports.console.level = 'info';
transports.file.level = 'info';
logger.info('Will be logged in both transports!');

winston supports customizable logging levels, defaulting to npm style logging levels. Levels must be specified at the time of creating your logger.

Using Custom Logging Levels

In addition to the predefined npm, syslog, and cli levels available in winston, you can also choose to define your own:

const myCustomLevels = {
  levels: {
    foo: 0,
    bar: 1,
    baz: 2,
    foobar: 3
  },
  colors: {
    foo: 'blue',
    bar: 'green',
    baz: 'yellow',
    foobar: 'red'
  }
};

const customLevelLogger = winston.createLogger({
  levels: myCustomLevels.levels
});

customLevelLogger.foobar('some foobar level-ed message');

Although there is slight repetition in this data structure, it enables simple encapsulation if you do not want to have colors. If you do wish to have colors, in addition to passing the levels to the Logger itself, you must make winston aware of them:

winston.addColors(myCustomLevels.colors);

This enables loggers using the colorize formatter to appropriately color and style the output of custom levels.

Additionally, you can also change background color and font style. For example,

baz: 'italic yellow',
foobar: 'bold red cyanBG'

Possible options are below.

  • Font styles: bold, dim, italic, underline, inverse, hidden, strikethrough.

  • Font foreground colors: black, red, green, yellow, blue, magenta, cyan, white, gray, grey.

  • Background colors: blackBG, redBG, greenBG, yellowBG, blueBG magentaBG, cyanBG, whiteBG

Colorizing Standard logging levels

To colorize the standard logging level add

winston.format.combine(
  winston.format.colorize(),
  winston.format.simple()
);

where winston.format.simple() is whatever other formatter you want to use. The colorize formatter must come before any formatters adding text you wish to color.

Colorizing full log line when json formatting logs

To colorize the full log line with the json formatter you can apply the following

winston.format.combine(
  winston.format.json(),
  winston.format.colorize({ all: true })
);

Transports

There are several core transports included in winston, which leverage the built-in networking and file I/O offered by Node.js core. In addition, there are additional transports written by members of the community.

Multiple transports of the same type

It is possible to use multiple transports of the same type e.g. winston.transports.File when you construct the transport.

const logger = winston.createLogger({
  transports: [
    new winston.transports.File({
      filename: 'combined.log',
      level: 'info'
    }),
    new winston.transports.File({
      filename: 'errors.log',
      level: 'error'
    })
  ]
});

If you later want to remove one of these transports you can do so by using the transport itself. e.g.:

const combinedLogs = logger.transports.find(transport => {
  return transport.filename === 'combined.log'
});

logger.remove(combinedLogs);

Adding Custom Transports

Adding a custom transport is easy. All you need to do is accept any options you need, implement a log() method, and consume it with winston.

const Transport = require('winston-transport');
const util = require('util');

//
// Inherit from `winston-transport` so you can take advantage
// of the base functionality and `.exceptions.handle()`.
//
module.exports = class YourCustomTransport extends Transport {
  constructor(opts) {
    super(opts);
    //
    // Consume any custom options here. e.g.:
    // - Connection information for databases
    // - Authentication information for APIs (e.g. loggly, papertrail,
    //   logentries, etc.).
    //
  }

  log(info, callback) {
    setImmediate(() => {
      this.emit('logged', info);
    });

    // Perform the writing to the remote service
    callback();
  }
};

Common Transport options

As every transport inherits from winston-transport, it's possible to set a custom format and a custom log level on each transport separately:

const logger = winston.createLogger({
  transports: [
    new winston.transports.File({
      filename: 'error.log',
      level: 'error',
      format: winston.format.json()
    }),
    new winston.transports.Http({
      level: 'warn',
      format: winston.format.json()
    }),
    new winston.transports.Console({
      level: 'info',
      format: winston.format.combine(
        winston.format.colorize(),
        winston.format.simple()
      )
    })
  ]
});

Exceptions

Handling Uncaught Exceptions with winston

With winston, it is possible to catch and log uncaughtException events from your process. With your own logger instance you can enable this behavior when it's created or later on in your applications lifecycle:

const { createLogger, transports } = require('winston');

// Enable exception handling when you create your logger.
const logger = createLogger({
  transports: [
    new transports.File({ filename: 'combined.log' })
  ],
  exceptionHandlers: [
    new transports.File({ filename: 'exceptions.log' })
  ]
});

// Or enable it later on by adding a transport or using `.exceptions.handle`
const logger = createLogger({
  transports: [
    new transports.File({ filename: 'combined.log' })
  ]
});

// Call exceptions.handle with a transport to handle exceptions
logger.exceptions.handle(
  new transports.File({ filename: 'exceptions.log' })
);

If you want to use this feature with the default logger, simply call .exceptions.handle() with a transport instance.

//
// You can add a separate exception logger by passing it to `.exceptions.handle`
//
winston.exceptions.handle(
  new winston.transports.File({ filename: 'path/to/exceptions.log' })
);

//
// Alternatively you can set `handleExceptions` to true when adding transports
// to winston.
//
winston.add(new winston.transports.File({
  filename: 'path/to/combined.log',
  handleExceptions: true
}));

To Exit or Not to Exit

By default, winston will exit after logging an uncaughtException. If this is not the behavior you want, set exitOnError = false

const logger = winston.createLogger({ exitOnError: false });

//
// or, like this:
//
logger.exitOnError = false;

When working with custom logger instances, you can pass in separate transports to the exceptionHandlers property or set handleExceptions on any transport.

Example 1
const logger = winston.createLogger({
  transports: [
    new winston.transports.File({ filename: 'path/to/combined.log' })
  ],
  exceptionHandlers: [
    new winston.transports.File({ filename: 'path/to/exceptions.log' })
  ]
});
Example 2
const logger = winston.createLogger({
  transports: [
    new winston.transports.Console({
      handleExceptions: true
    })
  ],
  exitOnError: false
});

The exitOnError option can also be a function to prevent exit on only certain types of errors:

function ignoreEpipe(err) {
  return err.code !== 'EPIPE';
}

const logger = winston.createLogger({ exitOnError: ignoreEpipe });

//
// or, like this:
//
logger.exitOnError = ignoreEpipe;

Rejections

Handling Uncaught Promise Rejections with winston

With winston, it is possible to catch and log unhandledRejection events from your process. With your own logger instance you can enable this behavior when it's created or later on in your applications lifecycle:

const { createLogger, transports } = require('winston');

// Enable rejection handling when you create your logger.
const logger = createLogger({
  transports: [
    new transports.File({ filename: 'combined.log' })
  ],
  rejectionHandlers: [
    new transports.File({ filename: 'rejections.log' })
  ]
});

// Or enable it later on by adding a transport or using `.rejections.handle`
const logger = createLogger({
  transports: [
    new transports.File({ filename: 'combined.log' })
  ]
});

// Call rejections.handle with a transport to handle rejections
logger.rejections.handle(
  new transports.File({ filename: 'rejections.log' })
);

If you want to use this feature with the default logger, simply call .rejections.handle() with a transport instance.

//
// You can add a separate rejection logger by passing it to `.rejections.handle`
//
winston.rejections.handle(
  new winston.transports.File({ filename: 'path/to/rejections.log' })
);

//
// Alternatively you can set `handleRejections` to true when adding transports
// to winston.
//
winston.add(new winston.transports.File({
  filename: 'path/to/combined.log',
  handleRejections: true
}));

Profiling

In addition to logging messages and metadata, winston also has a simple profiling mechanism implemented for any logger:

//
// Start profile of 'test'
//
logger.profile('test');

setTimeout(function () {
  //
  // Stop profile of 'test'. Logging will now take place:
  //   '17 Jan 21:00:00 - info: test duration=1000ms'
  //
  logger.profile('test');
}, 1000);

Also you can start a timer and keep a reference that you can call .done() on:

 // Returns an object corresponding to a specific timing. When done
 // is called the timer will finish and log the duration. e.g.:
 //
 const profiler = logger.startTimer();
 setTimeout(function () {
   profiler.done({ message: 'Logging message' });
 }, 1000);

All profile messages are set to 'info' level by default, and both message and metadata are optional. For individual profile messages, you can override the default log level by supplying a metadata object with a level property:

logger.profile('test', { level: 'debug' });

Querying Logs

winston supports querying of logs with Loggly-like options. See Loggly Search API. Specifically: File, Couchdb, Redis, Loggly, Nssocket, and Http.

const options = {
  from: new Date() - (24 * 60 * 60 * 1000),
  until: new Date(),
  limit: 10,
  start: 0,
  order: 'desc',
  fields: ['message']
};

//
// Find items logged between today and yesterday.
//
logger.query(options, function (err, results) {
  if (err) {
    /* TODO: handle me */
    throw err;
  }

  console.log(results);
});

Streaming Logs

Streaming allows you to stream your logs back from your chosen transport.

//
// Start at the end.
//
winston.stream({ start: -1 }).on('log', function(log) {
  console.log(log);
});

Further Reading

Using the Default Logger

The default logger is accessible through the winston module directly. Any method that you could call on an instance of a logger is available on the default logger:

const winston = require('winston');

winston.log('info', 'Hello distributed log files!');
winston.info('Hello again distributed logs');

winston.level = 'debug';
winston.log('debug', 'Now my debug messages are written to console!');

By default, no transports are set on the default logger. You must add or remove transports via the add() and remove() methods:

const files = new winston.transports.File({ filename: 'combined.log' });
const console = new winston.transports.Console();

winston.add(console);
winston.add(files);
winston.remove(console);

Or do it with one call to configure():

winston.configure({
  transports: [
    new winston.transports.File({ filename: 'somefile.log' })
  ]
});

For more documentation about working with each individual transport supported by winston see the winston Transports document.

Awaiting logs to be written in winston

Often it is useful to wait for your logs to be written before exiting the process. Each instance of winston.Logger is also a [Node.js stream]. A finish event will be raised when all logs have flushed to all transports after the stream has been ended.

const transport = new winston.transports.Console();
const logger = winston.createLogger({
  transports: [transport]
});

logger.on('finish', function (info) {
  // All `info` log messages has now been logged
});

logger.info('CHILL WINSTON!', { seriously: true });
logger.end();

It is also worth mentioning that the logger also emits an 'error' event if an error occurs within the logger itself which you should handle or suppress if you don't want unhandled exceptions:

//
// Handle errors originating in the logger itself
//
logger.on('error', function (err) { /* Do Something */ });

Working with multiple Loggers in winston

Often in larger, more complex, applications it is necessary to have multiple logger instances with different settings. Each logger is responsible for a different feature area (or category). This is exposed in winston in two ways: through winston.loggers and instances of winston.Container. In fact, winston.loggers is just a predefined instance of winston.Container:

const winston = require('winston');
const { format } = winston;
const { combine, label, json } = format;

//
// Configure the logger for `category1`
//
winston.loggers.add('category1', {
  format: combine(
    label({ label: 'category one' }),
    json()
  ),
  transports: [
    new winston.transports.Console({ level: 'silly' }),
    new winston.transports.File({ filename: 'somefile.log' })
  ]
});

//
// Configure the logger for `category2`
//
winston.loggers.add('category2', {
  format: combine(
    label({ label: 'category two' }),
    json()
  ),
  transports: [
    new winston.transports.Http({ host: 'localhost', port:8080 })
  ]
});

Now that your loggers are setup, you can require winston in any file in your application and access these pre-configured loggers:

const winston = require('winston');

//
// Grab your preconfigured loggers
//
const category1 = winston.loggers.get('category1');
const category2 = winston.loggers.get('category2');

category1.info('logging to file and console transports');
category2.info('logging to http transport');

If you prefer to manage the Container yourself, you can simply instantiate one:

const winston = require('winston');
const { format } = winston;
const { combine, label, json } = format;

const container = new winston.Container();

container.add('category1', {
  format: combine(
    label({ label: 'category one' }),
    json()
  ),
  transports: [
    new winston.transports.Console({ level: 'silly' }),
    new winston.transports.File({ filename: 'somefile.log' })
  ]
});

const category1 = container.get('category1');
category1.info('logging to file and console transports');

Routing Console transport messages to the console instead of stdout and stderr

By default the winston.transports.Console transport sends messages to stdout and stderr. This is fine in most situations; however, there are some cases where this isn't desirable, including:

  • Debugging using VSCode and attaching to, rather than launching, a Node.js process
  • Writing JSON format messages in AWS Lambda
  • Logging during Jest tests with the --silent option

To make the transport log use console.log(), console.warn() and console.error() instead, set the forceConsole option to true:

const logger = winston.createLogger({
  level: 'info',
  transports: [new winston.transports.Console({ forceConsole: true })]
});

Installation

npm install winston
yarn add winston

Run Tests

All of the winston tests are written with mocha, nyc, and assume. They can be run with npm.

npm test

Author: Charlie Robbins

Contributors: Jarrett Cruger, David Hyde, Chris Alderson

changelog

CHANGELOG

v3.9.0

Functionality changes

Dependency updates by @dependabot + CI autotesting

Documentation changes

Build Infrastructure changes

v3.8.2

Patch-level changes

Dependency updates by @dependabot + CI autotesting

v3.8.1

Patch-level changes

Dependency updates by @dependabot + CI autotesting

Dependency updates by @dependabot + CI autotesting

  • Bump @babel/core from 7.17.8 to 7.18.5
  • Bump eslint from 8.12.0 to 8.18.0
  • Bump @types/node from 17.0.23 to 18.0.0
  • Bump @babel/preset-env from 7.16.11 to 7.18.2
  • Bump @babel/cli from 7.17.6 to 7.17.10

Updates facilitating repo maintenance & enhancing documentation

Thanks especially to new contributors @zizifn, @arpad1337, @domiins, & @jeanpierrecarvalho!

v3.7.2 / 2022-04-04

This change reverts what should have been the feature-level update in 3.7.0 due to issue #2103 showing this to be breaking, unintentionally.

v3.7.1 / 2022-04-04

This change includes some minor updates to package-lock.json resolving npm audit failures: one in ansi-regex and another in minimist.

v3.7.0 / 2022-03-30

Feature-level updates:

  • [#1989] Fix: resolve issues with metadata and the associated overriding behavior (thanks @maverick1872, @wbt, @DABH, @fearphage and issue reporters)

Patch-level updates:

  • [#2075] Fix: add missing types for batching options for HTTP Transport (thanks @KylinDC)
  • Various dependencies updated, quality of life & maintainability changes, etc

v3.6.0 / 2022-02-12

  • [#2057] Fix potential memory leak by not waiting for process.nextTick before clearing pending callbacks (thanks @smashah!)
  • [#2071] Update to logform 2.4.0, which includes changes such as new options for JsonOptions and some typo fixes regarding levels
  • Various other dependencies are updated, tests are reorganized and cleaned up, etc. (thanks @wbt, @Maverick1872, @fearphage!)

v3.5.1 / 2022-01-31

This release reverts the changes made in PR #1896 which added stricter typing to the available log levels, and inadvertently broke use of custom levels with TypeScript (Issue #2047). Apologies for that!

v3.5.0 / 2022-01-27

This release includes the following, in sequence by first merge in group:

Feature updates:

  • Support batch mode in HTTP Transport (Issue #1970, PR #1998, thanks @BBE78!)

Patch-level updates:

  • Bump dependency versions (thanks @dependabot & @DABH!)
    • Bump @types/node from 16.11.12 to 17.0.8 (PR #2009)
    • Bump @babel/preset-env from 7.16.7 to 7.16.8 (#2036)
    • Bump @types/node from 17.0.8 to 17.0.9 (#2035)
    • Bump @babel/cli from 7.16.7 to 7.16.8 (#2034)
    • Bump @types/node from 17.0.9 to 17.0.10 (#2042)
    • Bump @babel/core from 7.16.7 to 7.16.12 (#2041)
    • Bump @babel/preset-env from 7.16.8 to 7.16.11 (#2040)
  • Fixing documentation syntax errors in transports code examples (#1916; thanks @romanzaycev!)
  • Fix missing type declarations, especially for .rejections (#1842, #1929, #2021; thanks @vanflux, @svaj, @glensc, & others!)
  • More narrowly typing the “level” string (#1896, thanks @yonas-g!)
  • Using a safer stringify, e.g. to avoid issues from circular structures, in the http transport (#2043, thanks @karlwir!)

Updates to the repo & project which don’t actually affect the running code:

  • Add a channel for reporting security vulnerabilities (#2024, thanks @JamieSlome!)
  • Add coverage tracking in CI & documentation (#2025 and #2028, thanks @fearphage!)
  • Update issue templates (#2030 and #2031, thanks @Maverick1872!)
  • Remove gitter link from README.md (#2027, thanks @DABH!)

Thanks also to maintainers @DABH, @fearphage, @Maverick1872, and @wbt for issue/PR shepherding and help across multiple parts of the release! If somebody got missed in the list of thanks, please forgive the accidental oversight and/or feel free to open a PR on this changelog.

v3.4.0 / 2022-01-10

Yesterday's release was done with a higher sense of urgency than usual due to vandalism in the colors package. This release:

  • ties up a loose end by including [#1973] to go with [#1824]
  • adds a missing http property in NpmConfigSetColors [#2004] (thanks @SimDaSong)
  • fixes a minor issue in the build/release process [#2014]
  • pins the version of the testing framework to avoid an issue with a test incorrectly failing [#2017]

The biggest change in this release, motivating the feature-level update, is [#2006] Make winston more ESM friendly, thanks to @miguelcobain.

Thanks also to @DABH, @wbt, and @fearphage for contributions and reviews!

v3.3.4 / 2022-01-09

Compared to v3.3.3, this version fixes some issues and includes some updates to project infrastructure, such as replacing Travis with Github CI and dependabot configuration. There have also been several relatively minor improvements to documentation, and incorporation of some updated dependencies. Dependency updates include a critical bug fix [#2008] in response to self-vandalism by the author of a dependency.

  • [#1964] Added documentation for how to use a new externally maintained Seq transport.
  • [#1712] Add default metadata when calling log with string level and message.
  • [#1824] Unbind event listeners on close
  • [#1961] Handle undefined rejections
  • [#1878] Correct boolean evaluation of empty-string value for eol option
  • [#1977] Improved consistency of object parameters for better test reliability

v3.3.3 / 2020-06-23

  • [#1820] Revert [#1807] to resolve breaking changes for Typescript users.

v3.3.2 / 2020-06-22

  • [#1814] Use a fork of diagnostics published to NPM to avoid git dependency.

v3.3.1 / 2020-06-21

  • [#1803], [#1807] Fix TypeScript bugs.
  • [#1740] Add space between info.message and meta.message.
  • [#1813] Avoid indirect storage-engine dependency.
  • [#1810] README updates.

v3.3.0 / 2020-06-21

  • [#1779] Fix property name in rejection handler.
  • [#1768] Exclude extraneous files from NPM package.
  • [#1364], [#1714] Don't remove transport from logger when transport error occurs.
  • [#1603] Expose child property on default logger.
  • [#1777] Allow HTTP transport to pass options to request.
  • [#1662] Add bearer auth capabilities to HTTP transport.
  • [#1612] Remove no-op in file transport.
  • [#1622], [#1623], [#1625] Typescript fixes.
  • (Minor) [#1647], [#1793] Update CI settings.
  • (Minor) [#1600], [#1605], [#1593], [#1610], [#1654], [#1656], [#1661], [#1651], [#1652], [#1677], [#1683], [#1684], [#1700], [#1697], [#1650], [#1705], [#1723], [#1737], [#1733], [#1743], [#1750], [#1754], [#1780], [#1778] README, Transports.md, other docs changes.
  • [#1672], [#1686], [#1772] Update dependencies.

v3.2.1 / 2019-01-29

UNBOUND PROTOTYPE AD INFINITUM EDITION

  • [1579], (@indexzero) Fallback to the "root" instance always created by

    createLogger for level convenience methods (e.g. .info(), .silly()). (Fixes [#1577]).
  • [#1539], (@indexzero) Assume message is the empty string when level-helper methods are invoked with no arguments (Fixed [#1501]).
  • [#1583], (@kibertoad) Add typings for defaultMeta (Fixes [#1582])
  • [#1586], (@kibertoad) Update dependencies.

v3.2.0 / 2019-01-26

SORRY IT TOO SO LONG EDITION

NOTE: this was our first release using Github Projects. See the 3.2.0 Release Project.

New Features!

  • [#1471], (@kibertoad) Implement child loggers.
  • [#1462], (@drazisil) Add handleRejection support.
    • [#1555], (@DABH) Add fixes from [#1355] to unhandled rejection handler.
  • [#1418], (@mfrisbey) Precompile ES6 syntax before publishing to npm.
    • [#1533], (@kibertoad) Update to Babel 7.
  • [#1562], (@indexzero) [fix] Better handling of new Error(string) throughout the pipeline(s). (Fixes [#1338], [#1486]).

Bug Fixes

  • [#1355], (@DABH) Fix issues with ExceptionHandler (Fixes [#1289]).
  • [#1463], (@SerayaEryn) Bubble transport warn events up to logger in addition to errors.
  • [#1480], [#1503], (@SerayaEryn) File tailrolling fix.
  • [#1483], (@soldair) Assign log levels to un-bound functions.
  • [#1513], (@TilaTheHun0) Set maxListeners for Console transport.
  • [#1521], (@jamesbechet) Fix Transform from readable-stream using CRA.
  • [#1434], (@Kouzukii) Fixes logger.query function (regression from 3.0.0)
  • [#1526], (@pixtron) Log file without .gz for tailable (Fixes [#1525]).
  • [#1559], (@eubnara) Fix typo related to exitOnError.
  • [#1556], (@adoyle-h) Support to create log directory if it doesn't exist for FileTransport.

New splat behavior

  • [#1552], (@indexzero) Consistent handling of meta with (and without) interpolation in winston and logform.
  • [#1499], (@DABH) Provide all of SPLAT to formats (Fixes [#1485]).
  • [#1485], (@mpabst) Fixing off-by-one when using both meta and splat.

Previously splat would have added a meta property for any additional info[SPLAT] beyond the expected number of tokens.

As of `logform@2.0.0`, format.splat assumes additional splat paramters (aka "metas") are objects and merges enumerable properties into the info. e.g. BE ADVISED previous "metas" that were not objects will very likely lead to odd behavior. e.g.

const { createLogger, format, transports } = require('winston');
const { splat } = format;
const { MESSAGE, LEVEL, SPLAT } = require('triple-beam');

const logger = createLogger({
  format: format.combine(
    format.splat(),
    format.json()
  ),
  transports: [new transports.Console()]
});

// Expects two tokens, but four splat parameters provided.
logger.info(
  'Let us %s for %j',   // message
  'objects',           // used for %s
  { label: 'sure' },   // used for %j
  'lol', ['ok', 'why'] // Multiple additional meta values
);

// winston < 3.2.0 && logform@1.x behavior:
// Added "meta" property.
//
// { level: 'info',
//   message: 'Let us objects for {"label":"sure"}',
//   meta: ['lol', ['ok', 'why']],
//   [Symbol(level)]: 'info',
//   [Symbol(message)]: 'Let us %s for %j',
//   [Symbol(splat)]: [ 'objects', { label: 'sure' } ] }

// winston >= 3.2.0 && logform@2.x behavior: Enumerable properties
// assigned into `info`. Since **strings and Arrays only have NUMERIC
// enumerable properties we get this behavior!**
//
// { '0': 'ok',
//   '1': 'why',
//   '2': 'l',
//   level: 'info',
//   message: 'Let us objects for {"label":"sure"}',
//   [Symbol(level)]: 'info',
//   [Symbol(message)]: 'Let us %s for %j',
//   [Symbol(splat)]: [ 'objects', { label: 'sure' } ] }

Maintenance & Documentation

  • Documentation Updates
    • [#1410], (@hakanostrom) Add docs reference to transport for Cloudant.
    • [#1467], (@SeryaEryn) Add fast-file-rotate transport to transport.md.
    • [#1488], (@adamcohen) Fix multi logger documentation.
    • [#1531], (@mapleeit) Add links to transports.
    • [#1548], (@ejmartin504) Fix README.md for awaiting logs.
    • [#1554], (@indexzero) Document the solution to [#1486] as by design.
    • Other small improvements: [#1509].
  • Improved TypeScript support
    • [#1470], (@jd-carroll) Export all transport options (Fixes [#1469]).
    • [#1474], (@jd-carroll) Correct import to avoid conflict (Fixed [#1472]).
    • [#1546], (@alewiahmed) Add consoleWarnLevels field to the ConsoleTransportOptions interface type definition.
    • [#1557], (@negezor) Add missing child() method.
  • Dependency management
    • [#1560], (@kibertoad) Update dependencies.
    • [#1512], (@SerayaEryn) Add node@11 and disallow failures on node@10.
    • [#1516], (@SerayaEryn) Update readable-stream to v3.0.6.
    • [#1534], (@kibertoad) Update @types/node, nyc, and through2.

v3.1.0 / 2018-08-22

RELEASES ON A PLANE EDITION

  • Minor TypeScript fixes [#1362], [#1395], [#1440]
  • Fix minor typos [#1359], [#1363], [#1372], [#1378], [#1390]
  • [#1373], (@revik): Add consoleWarnLevels property to console transport options for console.warn browser support.
  • [#1394], (@bzoz): Fix tests on Windows.
  • [#1447], (@dboshardy): Support transport name option to override default names for built-in transports.
  • [#1420], (@ledbit): Fix file rotation with tailing: true (Fixes [#1450], [#1194]).
  • [#1352], (@lutovich): Add isLevelEnabled(string) & isXXXEnabled() to Logger class.
  • Dependency management
    • Regenerate package-lock.json.
    • Upgrade to colors@^1.3.2 (Fixes [#1439]).
    • Upgrade to logform@^1.9.1.
    • Upgrade to diagnostics@^1.1.1.
    • Upgrade to @types/node@^10.9.3.
    • Upgrade to assume@^2.1.0.
    • Upgrade to hock@^1.3.3.
    • Upgrade to mocha@^5.2.0.
    • Upgrade to nyc@^13.0.1.
    • Upgrade to split2@^3.0.0.

v3.0.0 / 2018-06-12

GET IN THE CHOPPA EDITION

  • [#1332], (@DABH): logger.debug is sent to stderr (Fixed [#1024])
  • [#1328], (@ChrisAlderson): Logger level doesn't update transports level (Fixes [#1191]).
  • [#1356], (@indexzero) Move splat functionality into logform. (Fixes [#1298]).
  • [#1340], (@indexzero): Check log.length when evaluating "legacyness" of transports (Fixes [#1280]).
  • [#1346], (@indexzero): Implement _final from Node.js streams. (Related to winston-transport#24, Fixes [#1250]).
  • [#1347], (@indexzero): Wrap calls to format.transform with try / catch (Fixes [#1261]).
  • [#1357], (@indexzero): Remove paddings as we have no use for it in the current API.
  • [TODO]: REMAINS OPEN, NO PR (Fixes [#1289])
  • Documentation
    • [#1301], (@westonpace) Cleaned up some of the documentation on colorize to address concerns in [#1095].
    • First pass at a heavy refactor of docs/transports.md.
  • Dependency management
    • Regenerate package-lock.json.
    • Upgrade to logform@^1.9.0.

v3.0.0-rc6 / 2018-05-30

T-MINUS 6-DAY TO WINSTON@3 EDITION

  • Document that we are pushing for a June 5th, 2018 release of `winston@3.0.0`
  • [#1287], (@DABH) Added types for Typescript.
    • [#1335] Typescript: silent is boolean.
    • [#1323] Add level method to default logger.
  • [#1286], (@ChrisAlderson) Migrate codebase to ES6
    • [#1324], (@ChrisAlderson) Fix regression introduced by ES6 migration for exception handling.
    • [#1333], (@ChrisAlderson) Fix removing all loggers from a container.
  • [#1291], [#1294], [#1318], (@indexzero, @ChrisAlderson, @mempf) Improvements to File transport core functionality. Fixes [#1194].
  • [#1311], (@ChrisAlderson) Add eol option to Stream transport.
  • [#1297], (@ChrisAlderson) Move winston.config to triple-beam. Expose for backwards compatibility.
  • [#1320], (@ChrisAlderson) Enhance tests to run on Windows.
  • Internal project maintenance
    • Bump to `winston-transport@4.0.0which may cause incompatibilities if your custom transport does not explicitly requirewinston-transport` itself.
    • [#1292], (@ChrisAlderson) Add node v10 to TravisCI build matrix.
    • [#1296], (@indexzero) Improve UPGRADE-3.0.md. Add Github Issue Template.
    • Remove "npm run report" in favor of reports being automatically generate.
    • Update logform, triple-beam, and winston-transport to latest.

Special thanks to our newest winston core team member – @ChrisAlderson for helping make `winston@3.0.0` a reality next week!

v3.0.0-rc5 / 2018-04-20

UNOFFICIAL NATIONAL HOLIDAY EDITION

  • [#1281] Use Buffer.alloc and Buffer.from instead of new Buffer.
  • Better browser support
    • [#1142] Move common tailFile to a separate file
    • [#1279] Use feature detection to be safer for browser usage.
  • MOAR Docs!
    • Document that we are pushing for a May 29th, 2018 release of `winston@3.0.0`
    • Add David Hyde as official contributor.
    • [#1278] Final Draft of Upgrade Guide in UPGRADE-3.0.md
    • Merge Roadmap from 3.0.0.md into CONTRIBUTING.md and other improvements to CONTRIBUTING.md
  • Improve & expand examples
    • [#1175] Add more copy about printf formats based on issue feedback.
    • [#1134] Add sampleto document timestamps more clearly as an example.
    • [#1273] Add example using multiple formats.
    • [#1250] Add an example illustrating the "finish" event for AWS Lambda scenarios.
    • Use simple format to better show that humanReadableUnhandledException is now the default message format.
    • Add example to illustrate that example code from winston-transport README.md is correct.
  • Update devDependencies
    • Bump assume to ^2.0.1.
    • Bump winston-compat to ^0.1.1.

v3.0.0-rc4 / 2018-04-06

IF A TREE FALLS IN THE FORREST DOES IT MAKE A LOG EDITION

  • (@indexzero, @dabh) Add support for { silent } option to
    require('winston').Logger;
    require('winston-transport').TransportStream;
  • Better browser support
    • [#1145], (@Jasu) Replace isstream with is-stream to make stream detection work in browser.
    • [#1146], (@Jasu) Rename query to different than function name, to support Babel 6.26.
  • Better Typescript support in all supporting libraries
  • Update documentation
    • (@indexzero) Correct link to upgrade guide. Fixes #1255.
    • [#1258], (@morenoh149) Document how to colorize levels. Fixes #1135.
    • [#1246], (@KlemenPlazar) Update colors argument when adding custom colors
    • Update CONTRIBUTING.md
    • [#1239], (@dabh) Add changelog entries for v3.0.0-rc3
    • Add example showing that { level } can be deleted from info objects because Symbol.for('level') is what winston uses internally. Fixes #1184.

v3.0.0-rc3 / 2018-03-16

I GOT NOTHING EDITION

  • [#1195], (@Nilegfx) Fix type error when creating new stream.Stream()
  • [#1109], (@vsetka) Fix file transprot bug where self.filename was not being updated on ENOENT
  • [#1153], (@wizardnet972) Make prototype methods return like the original method
  • [#1234], (@guiguan, @indexzero) Add tests for properly handling logging of undefined, null and Error values
  • [#1235], (@indexzero) Add example demonstrating how meta objects BECOME the info object
  • Minor fixes to docs & examples: [#1232], [#1185]

v3.0.0-rc2 / 2018-03-09

MAINTENANCE RESUMES EDITION

  • [#1209], (@dabh) Use new version of colors, solving a number of issues.
  • [#1197], (@indexzero) Roadmap & guidelines for contributors.
  • [#1100] Require the package.json by its full name.
  • [#1149] Updates async to latest (2.6.0)
  • [#1228], (@mcollina) Always pass a function to fs.close.
  • Minor fixes to docs & examples: [#1177], [#1182], [#1208], [#1198], [#1165], [#1110], [#1117], [#1097], [#1155], [#1084], [#1141], [#1210], [#1223].

v3.0.0-rc1 / 2017-10-19

OMG THEY FORGOT TO NAME IT EDITION

  • Fix file transport improper binding of _onDrain and _onError #1104

v3.0.0-rc0 / 2017-10-02

IT'S-DONE.GIF EDITION

See UPGRADE-3.0.md for a complete & living upgrade guide.

See 3.0.0.md for a list of remaining RC tasks.

  • Rewrite of core logging internals: Logger & Transport are now implemented using Node.js objectMode streams.
  • Your transports should not break: Special attention has been given to ensure backwards compatibility with existing transports. You will likely see this: ` YourTransport is a legacy winston transport. Consider upgrading to winston@3:
  • Upgrade docs: https://github.com/winstonjs/winston/tree/master/UPGRADE.md `
  • filters, rewriters, and common.log are now formats: winston.format offers a simple mechanism for user-land formatting & style features. The organic & frankly messy growth of common.log is of the past; these feature requests can be implemented entirely outside of winston itself. ` js const { createLogger, format, transports } = require('winston'); const { combine, timestamp, label, printf } = format;

const myFormat = printf(info => { return ${info.timestamp} [${info.label}] ${info.level}: ${info.message}; });

const logger = createLogger({ combine( label({ label: 'right meow!' }), timestamp(), myFormat ), transports: [new transports.Console()] });

- **Increased modularity:** several subsystems are now stand-alone packages:
  - [logform] exposed as `winston.format`
  - [winston-transport] exposed as `winston.Transport`
  - [abstract-winston-transport] used for reusable unit test suites for transport authors.
- **`2.x` branch will get little to no maintenance:** no feature requests will be accepted – only a limited number of open PRs will be merged. Hoping the [significant performance benefits][perf-bench] incentivizes folks to upgrade quickly. Don't agree? Say something!
- **No guaranteed support for `node@4` or below:** all code will be migrated to ES6 over time. This release was started when ES5 was still a hard requirement due to the current LTS needs.

## v2.4.0 / 2017-10-01
### ZOMFG WINSTON@3.0.0-RC0 EDITION

- [#1036] Container.add() 'filters' and 'rewriters' option passing to logger.
- [#1066] Fixed working of "humanReadableUnhandledException" parameter when additional data is added in meta.
- [#1040] Added filtering by log level
- [#1042] Fix regressions brought by `2.3.1`.
  - Fix regression on array printing.
  - Fix regression on falsy value.
- [#977] Always decycle objects before cloning.
  - Fixes [#862]
  - Fixes [#474]
  - Fixes [#914]
- [57af38a] Missing context in `.lazyDrain` of `File` transport.
- [178935f] Suppress excessive Node warning from `fs.unlink`.
- [fcf04e1] Add `label` option to `File` transport docs.
- [7e736b4], [24300e2] Added more info about undocumented `winston.startTimer()` method.
- [#1076], [#1082], [#1029], [#989], [e1e7188] Minor grammatical & style updates to `README.md`.

## v2.3.1 / 2017-01-20
### WELCOME TO THE APOCALYPSE EDITION

- [#868](https://github.com/winstonjs/winston/pull/868), Fix 'Maximum call stack size exceeded' error with custom formatter.

## v2.3.0 / 2016-11-02
### ZOMG WHY WOULD YOU ASK EDITION

- Full `CHANGELOG.md` entry forthcoming. See [the `git` diff for `2.3.0`](https://github.com/winstonjs/winston/compare/2.2.0...2.3.0) for now.

## v2.2.0 / 2016-02-25
### LEAVING CALIFORNIA EDITION

- Full `CHANGELOG.md` entry forthcoming. See [the `git` diff for `2.2.0`](https://github.com/winstonjs/winston/compare/2.1.1...2.2.0) for now.

## v2.1.1 / 2015-11-18
### COLOR ME IMPRESSED EDITION

- [#751](https://github.com/winstonjs/winston/pull/751), Fix colors not appearing in non-tty environments. Fixes [#609](https://github.com/winstonjs/winston/issues/609), [#616](https://github.com/winstonjs/winston/issues/616), [#669](https://github.com/winstonjs/winston/issues/669), [#648](https://github.com/winstonjs/winston/issues/648) (`fiznool`).
- [#752](https://github.com/winstonjs/winston/pull/752)     Correct syslog RFC number. 5424 instead of 524. (`jbenoit2011`)

## v2.1.0 / 2015-11-03
### TEST ALL THE ECOSYSTEM EDITION

- [#742](https://github.com/winstonjs/winston/pull/742), [32d52b7](https://github.com/winstonjs/winston/commit/32d52b7) Distribute common test files used by transports in the `winston` ecosystem.

## v2.0.1 / 2015-11-02
### BUGS ALWAYS HAPPEN OK EDITION

- [#739](https://github.com/winstonjs/winston/issues/739), [1f16861](https://github.com/winstonjs/winston/commit/1f16861) Ensure that `logger.log("info", undefined)` does not throw.

## v2.0.0 / 2015-10-29
### OMG IT'S MY SISTER'S BIRTHDAY EDITION

#### Breaking changes

**Most important**
- **[0f82204](https://github.com/winstonjs/winston/commit/0f82204) Move `winston.transports.DailyRotateFile` [into a separate module](https://github.com/winstonjs/winston-daily-rotate-file)**: `require('winston-daily-rotate-file');`
- **[fb9eec0](https://github.com/winstonjs/winston/commit/fb9eec0) Reverse log levels in `npm` and `cli` configs to conform to [RFC524](https://tools.ietf.org/html/rfc5424). Fixes [#424](https://github.com/winstonjs/winston/pull/424) [#406](https://github.com/winstonjs/winston/pull/406) [#290](https://github.com/winstonjs/winston/pull/290)**
- **[8cd8368](https://github.com/winstonjs/winston/commit/8cd8368) Change the method signature to a `filter` function to be consistent with `rewriter` and log functions:**
``` js
function filter (level, msg, meta, inst) {
  // Filter logic goes here...
}

Other breaking changes

  • e0c9dde Remove winston.transports.Webhook. Use winston.transports.Http instead.
  • f71e638 Remove Logger.prototype.addRewriter and Logger.prototype.addFilter since they just push to an Array of functions. Use logger.filters.push or logger.rewriters.push explicitly instead.
  • a470ab5 No longer respect the handleExceptions option to new winston.Logger. Instead just pass in the exceptionHandlers option itself.
  • 8cb7048 Removed Logger.prototype.extend functionality

New features

  • 3aa990c Added Logger.prototype.configure which now contains all logic previously in the winston.Logger constructor function. (indexzero)
  • #726 Update .npmignore (coreybutler)
  • #700 Add an eol option to the Console transport. (aquavitae)
  • #731 Update lib/transports.js for better static analysis. (indexzero)

Fixes, refactoring, and optimizations. OH MY!

  • #632 Allow File transport to be an objectMode writable stream. (stambata)
  • #527, 163f4f9, 3747ccf Performance optimizations and string interpolation edge cases (indexzero)
  • f0edafd Code cleanup for reability, ad-hoc styleguide enforcement (indexzero)

v1.1.1 - v1.1.2 / 2015-10

MINOR FIXES EDITION

Notable changes

  • 727 Fix "raw" mode (jcrugzz)
  • 703 Do not modify Error or Date objects when logging. Fixes #610 (harriha).

v1.1.0 / 2015-10-09

GREETINGS FROM CARTAGENA EDITION

Notable Changes

  • #721 Fixed octal literal to work with node 4 strict mode (wesleyeff)
  • #630 Add stderrLevels option to Console Transport and update docs (paulhroth)
  • #626 Add the logger (this) in the fourth argument in the rewriters and filters functions (christophehurpeau)
  • #623 Fix Console Transport's align option tests (paulhroth, kikobeats)
  • #692 Adding winston-aws-cloudwatch to transport docs (timdp)

v1.0.2 2015-09-25

LET'S TALK ON GITTER EDITION

Notable Changes

  • de80160 Add Gitter badge (The Gitter Badger)
  • 44564de [fix] Correct listeners in logException. Fixes #218 #213 #327. (indexzero)
  • 45b1eeb [fix] Get tailFile function working on latest/all node versions (Christopher Jeffrey)
  • c6d45f9 Fixed event subscription on close (Roman Stetsyshin)

Other changes

v1.0.1 / 2015-06-26

YAY DOCS EDITION

v1.0.0 / 2015-04-07

OMG 1.0.0 FINALLY EDITION

Breaking Changes

  • #587 Do not extend String prototypes as a side effect of using colors. (kenperkins)
  • #581 File transports now emit error on error of the underlying streams after maxRetries attempts. (ambbell).
  • #583, 92729a Use os.EOL for all file writing by default. (Mik13, indexzero)
  • #532 Delete logger instance from Container when close event is emitted. (snater)
  • #380 Rename duration to durationMs, which is now a number a not a string ending in ms. (neoziro)
  • #253 Do not set a default level. When level is falsey on any Transport instance, any Logger instance uses the configured level (instead of the Transport level) (jstamerj).

Other changes

  • b83de62 Fix rendering of stack traces.
  • c899cc Update documentation (Fixes #549)
  • #551 Filter metadata along with messages
  • #578 Fixes minor issue with maxFiles in File transport (Fixes #556).
  • #560 Added showLevel support to File transport.
  • #558 Added showLevel support to Console transport.

v0.9.0 / 2015-02-03

  • #496 Updated default option handling for CLI (oojacoboo).
  • f37634b [dist] Only support node >= 0.8.0. (indexzero)
  • 91a1e90, 50163a0 Fix #84 Enable a better unhandled exception experience (samz)
  • 8b5fbcd #448 Added tailable option to file transport which rolls files backwards instead of creating incrementing appends. Implements #268 (neouser99)
  • a34f7d2 Custom log formatter functionality were added. (Melnyk Andii)
  • 4c08191 Added showLevel flag to common.js, file*, memory and console transports. (Tony Germaneri)
  • 64ed8e0 Adding custom pretty print function test. (Alberto Pose)
  • 3872dfb Adding prettyPrint parameter as function example. (Alberto Pose)
  • 2b96eee implemented filters #526 (Chris Oloff)
  • 72273b1 Added the options to colorize only the level, only the message or all. Default behavior is kept. Using true will only colorize the level and false will not colorize anything. (Michiel De Mey)
  • 178e8a6 Prevent message from meta input being overwritten (Leonard Martin)
  • 270be86 [api] Allow for transports to be removed by their string name [test fix] Add test coverage for multiple transports of the same type added in #187. [doc] Document using multiple transports of the same type (indexzero)
  • 0a848fa Add depth options for meta pretty print (Loïc Mahieu)
  • 106b670 Allow debug messages to be sent to stdout (John Frizelle)
  • ad2d5e1 [fix] Handle Error instances in a sane way since their properties are non-enumerable by default. Fixes #280. (indexzero)
  • 5109dd0 [fix] Have a default until before a default from. Fixes #478. (indexzero)
  • d761960 Fix logging regular expression objects (Chasen Le Hara)
  • 2632eb8 Add option for EOL chars on FileTransport (José F. Romaniello)
  • bdecce7 Remove duplicate logstash option (José F. Romaniello)
  • 7a01f9a Update declaration block according to project's style guide (Ricardo Torres)
  • ae27a19 Fixes #306: Can't set customlevels to my loggers (RangeError: Maximum call stack size exceeded) (Alberto Pose)
  • 1ba4f51 [fix] Call res.resume() in HttpTransport to get around known issues in streams2. (indexzero)
  • 39e0258 Updated default option handling for CLI (Jacob Thomason)
  • 8252801 Added logstash support to console transport (Ramon Snir)
  • 18aa301 Module isStream should be isstream (Michael Neil)
  • 2f5f296 options.prettyPrint can now be a function (Matt Zukowski)
  • a87a876 Adding rotationFormat prop to file.js (orcaman)
  • ff187f4 Allow custom exception level (jupiter)

0.8.3 / 2014-11-04

0.8.2 / 2014-11-04

0.8.1 / 2014-10-06

0.8.0 / 2014-09-15

0.6.2 / 2012-07-08

  • Added prettyPrint option for console logging
  • Multi-line values for conditional returns are not allowed
  • Added acceptance of stringify option
  • Fixed padding for log levels