@@ -115,6 +115,7 @@ transports may produce a high memory usage issue.
115
115
* [ Using the default logger] ( #using-the-default-logger )
116
116
* [ Awaiting logs to be written in ` winston ` ] ( #awaiting-logs-to-be-written-in-winston )
117
117
* [ 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 )
118
119
* [ Installation] ( #installation )
119
120
* [ Run Tests] ( #run-tests )
120
121
@@ -148,7 +149,7 @@ const logger = winston.createLogger({
148
149
});
149
150
```
150
151
151
- A logger accepts the following parameters:
152
+ A logger accepts the following parameters:
152
153
153
154
| Name | Default | Description |
154
155
| ------------- | --------------------------- | --------------- |
@@ -260,7 +261,7 @@ Several of the formats in `logform` itself add additional properties:
260
261
| ` label ` | ` label() ` | Custom label associated with each message. |
261
262
| ` ms ` | ` ms() ` | Number of milliseconds since the previous log message. |
262
263
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
264
265
maintained by ` Symbol ` properties:_
265
266
266
267
- ` Symbol.for('level') ` _ ** (READ-ONLY)** :_ equal to ` level ` property.
@@ -290,7 +291,7 @@ console.log(SPLAT === Symbol.for('splat'));
290
291
// true
291
292
```
292
293
293
- > ** NOTE:** any ` { message } ` property in a ` meta ` object provided will
294
+ > ** NOTE:** any ` { message } ` property in a ` meta ` object provided will
294
295
> automatically be concatenated to any ` msg ` already provided: For
295
296
> example the below will concatenate 'world' onto 'hello':
296
297
>
@@ -380,10 +381,10 @@ const logger = createLogger({
380
381
transports: [new transports.Console ()]
381
382
});
382
383
383
- // info: test message my string {}
384
+ // info: test message my string {}
384
385
logger .log (' info' , ' test message %s' , ' my string' );
385
386
386
- // info: test message 123 {}
387
+ // info: test message 123 {}
387
388
logger .log (' info' , ' test message %d' , 123 );
388
389
389
390
// info: test message first second {number: 123}
@@ -450,7 +451,7 @@ method: `transform(info, opts)` and return the mutated `info`:
450
451
They are expected to return one of two things:
451
452
452
453
- ** 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
454
455
built-in formats consider ` info ` mutable, but [ immutablejs] is being
455
456
considered for future releases.
456
457
- ** A falsey value** indicating that the ` info ` argument should be ignored by the
@@ -1198,6 +1199,25 @@ const category1 = container.get('category1');
1198
1199
category1 .info (' logging to file and console transports' );
1199
1200
```
1200
1201
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
+
1201
1221
## Installation
1202
1222
1203
1223
``` bash
@@ -1244,4 +1264,4 @@ npm test
1244
1264
[ Charlie Robbins ] : http://github.com/indexzero
1245
1265
[ Jarrett Cruger ] : https://github.com/jcrugzz
1246
1266
[ David Hyde ] : https://github.com/dabh
1247
- [ Chris Alderson ] : https://github.com/chrisalderson
1267
+ [ Chris Alderson ] : https://github.com/chrisalderson
0 commit comments