@@ -115,6 +115,7 @@ transports may produce a high memory usage issue.
115115 * [ Using the default logger] ( #using-the-default-logger )
116116 * [ Awaiting logs to be written in ` winston ` ] ( #awaiting-logs-to-be-written-in-winston )
117117 * [ Working with multiple Loggers in ` winston ` ] ( #working-with-multiple-loggers-in-winston )
118+ * [ Routing Console transport messages to the console instead of stdout and stderr] ( #routing-console-transport-messages-to-the-console-instead-of-stdout-and-stderr )
118119* [ Installation] ( #installation )
119120* [ Run Tests] ( #run-tests )
120121
@@ -148,7 +149,7 @@ const logger = winston.createLogger({
148149});
149150```
150151
151- A logger accepts the following parameters:
152+ A logger accepts the following parameters:
152153
153154| Name | Default | Description |
154155| ------------- | --------------------------- | --------------- |
@@ -260,7 +261,7 @@ Several of the formats in `logform` itself add additional properties:
260261| ` label ` | ` label() ` | Custom label associated with each message. |
261262| ` ms ` | ` ms() ` | Number of milliseconds since the previous log message. |
262263
263- As a consumer you may add whatever properties you wish – _ internal state is
264+ As a consumer you may add whatever properties you wish – _ internal state is
264265maintained by ` Symbol ` properties:_
265266
266267- ` Symbol.for('level') ` _ ** (READ-ONLY)** :_ equal to ` level ` property.
@@ -290,7 +291,7 @@ console.log(SPLAT === Symbol.for('splat'));
290291// true
291292```
292293
293- > ** NOTE:** any ` { message } ` property in a ` meta ` object provided will
294+ > ** NOTE:** any ` { message } ` property in a ` meta ` object provided will
294295> automatically be concatenated to any ` msg ` already provided: For
295296> example the below will concatenate 'world' onto 'hello':
296297>
@@ -380,10 +381,10 @@ const logger = createLogger({
380381 transports: [new transports.Console ()]
381382});
382383
383- // info: test message my string {}
384+ // info: test message my string {}
384385logger .log (' info' , ' test message %s' , ' my string' );
385386
386- // info: test message 123 {}
387+ // info: test message 123 {}
387388logger .log (' info' , ' test message %d' , 123 );
388389
389390// info: test message first second {number: 123}
@@ -450,7 +451,7 @@ method: `transform(info, opts)` and return the mutated `info`:
450451They are expected to return one of two things:
451452
452453- ** An ` info ` Object** representing the modified ` info ` argument. Object
453- references need not be preserved if immutability is preferred. All current
454+ references need not be preserved if immutability is preferred. All current
454455built-in formats consider ` info ` mutable, but [ immutablejs] is being
455456considered for future releases.
456457- ** A falsey value** indicating that the ` info ` argument should be ignored by the
@@ -1198,6 +1199,25 @@ const category1 = container.get('category1');
11981199category1 .info (' logging to file and console transports' );
11991200```
12001201
1202+ ### Routing Console transport messages to the console instead of stdout and stderr
1203+
1204+ By default the ` winston.transports.Console ` transport sends messages to ` stdout ` and ` stderr ` . This
1205+ is fine in most situations; however, there are some cases where this isn't desirable, including:
1206+
1207+ - Debugging using VSCode and attaching to, rather than launching, a Node.js process
1208+ - Writing JSON format messages in AWS Lambda
1209+ - Logging during Jest tests with the ` --silent ` option
1210+
1211+ To make the transport log use ` console.log() ` , ` console.warn() ` and ` console.error() `
1212+ instead, set the ` forceConsole ` option to ` true ` :
1213+
1214+ ``` js
1215+ const logger = winston .createLogger ({
1216+ level: ' info' ,
1217+ transports: [new winston.transports.Console ({ forceConsole: true })]
1218+ });
1219+ ```
1220+
12011221## Installation
12021222
12031223``` bash
@@ -1244,4 +1264,4 @@ npm test
12441264[ Charlie Robbins ] : http://github.com/indexzero
12451265[ Jarrett Cruger ] : https://github.com/jcrugzz
12461266[ David Hyde ] : https://github.com/dabh
1247- [ Chris Alderson ] : https://github.com/chrisalderson
1267+ [ Chris Alderson ] : https://github.com/chrisalderson
0 commit comments