Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme with forceConsole info #2493

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 63 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,50 @@ transports may produce a high memory usage issue.

## Table of contents

* [Motivation](#motivation)
* [Quick Start](#quick-start)
* [Usage](#usage)
* [Table of Contents](#table-of-contents)
* [Logging](#logging)
* [Creating your logger](#creating-your-own-logger)
* [Streams, `objectMode`, and `info` objects](#streams-objectmode-and-info-objects)
* [Formats]
* [Combining formats](#combining-formats)
* [String interpolation](#string-interpolation)
* [Filtering `info` Objects](#filtering-info-objects)
* [Creating custom formats](#creating-custom-formats)
* [Logging levels]
* [Using logging levels](#using-logging-levels)
* [Using custom logging levels](#using-custom-logging-levels)
* [Transports]
* [winston](#winston)
neilenns marked this conversation as resolved.
Show resolved Hide resolved
* [winston@3](#winston3)
* [Looking for `winston@2.x` documentation?](#looking-for-winston2x-documentation)
* [Motivation](#motivation)
* [Quick Start](#quick-start)
* [Usage](#usage)
* [Table of contents](#table-of-contents)
* [Logging](#logging)
* [Creating your own Logger](#creating-your-own-logger)
* [Creating child loggers](#creating-child-loggers)
* [Streams, `objectMode`, and `info` objects](#streams-objectmode-and-info-objects)
* [Formats](#formats)
* [Combining formats](#combining-formats)
* [String interpolation](#string-interpolation)
* [Filtering `info` Objects](#filtering-info-objects)
* [Creating custom formats](#creating-custom-formats)
* [Logging Levels](#logging-levels)
* [Using Logging Levels](#using-logging-levels)
* [Using Custom Logging Levels](#using-custom-logging-levels)
* [Colorizing Standard logging levels](#colorizing-standard-logging-levels)
* [Colorizing full log line when json formatting logs](#colorizing-full-log-line-when-json-formatting-logs)
* [Transports](#transports)
* [Multiple transports of the same type](#multiple-transports-of-the-same-type)
* [Adding Custom Transports](#adding-custom-transports)
* [Common Transport options](#common-transport-options)
* [Exceptions](#exceptions)
* [Handling Uncaught Exceptions with winston](#handling-uncaught-exceptions-with-winston)
* [To Exit or Not to Exit](#to-exit-or-not-to-exit)
* [Rejections](#rejections)
* [Handling Uncaught Promise Rejections with winston](#handling-uncaught-promise-rejections-with-winston)
* [Profiling](#profiling)
* [Streaming Logs](#streaming-logs)
* [Querying Logs](#querying-logs)
* [Further Reading](#further-reading)
* [Using the default logger](#using-the-default-logger)
* [Awaiting logs to be written in `winston`](#awaiting-logs-to-be-written-in-winston)
* [Working with multiple Loggers in `winston`](#working-with-multiple-loggers-in-winston)
* [Installation](#installation)
* [Run Tests](#run-tests)
* [Exceptions](#exceptions)
* [Handling Uncaught Exceptions with winston](#handling-uncaught-exceptions-with-winston)
* [To Exit or Not to Exit](#to-exit-or-not-to-exit)
* [Example 1](#example-1)
* [Example 2](#example-2)
* [Rejections](#rejections)
* [Handling Uncaught Promise Rejections with winston](#handling-uncaught-promise-rejections-with-winston)
* [Profiling](#profiling)
* [Querying Logs](#querying-logs)
* [Streaming Logs](#streaming-logs)
* [Further Reading](#further-reading)
* [Using the Default Logger](#using-the-default-logger)
* [Awaiting logs to be written in `winston`](#awaiting-logs-to-be-written-in-winston)
* [Working with multiple Loggers in winston](#working-with-multiple-loggers-in-winston)
* [Routing Console transport messages to the console instead of stdout and stderr](#routing-console-transport-messages-to-the-console-instead-of-stdout-and-stderr)
* [Installation](#installation)
* [Run Tests](#run-tests)
* [Author: Charlie Robbins](#author-charlie-robbins)
* [Contributors: Jarrett Cruger, David Hyde, Chris Alderson](#contributors-jarrett-cruger-david-hyde-chris-alderson)
neilenns marked this conversation as resolved.
Show resolved Hide resolved

## Logging

Expand Down Expand Up @@ -1198,6 +1209,28 @@ 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:
neilenns marked this conversation as resolved.
Show resolved Hide resolved

* 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`:

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

## Installation

``` bash
Expand Down
Loading