Skip to content

Commit 63509be

Browse files
authored
Document the solution to #1486. (#1554)
* [doc] Document the solution to #1486. * [doc] Show both in example. * [doc] Update the examples.
1 parent 1873058 commit 63509be

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ treated as immutable by all code.
235235
- `Symbol.for('message'):` complete string message set by "finalizing
236236
formats": `json`, `logstash`, `printf`, `prettyPrint`, and `simple`.
237237

238+
> **NOTE:** the `message` and `level` properties are considered reserved.
239+
> Please be aware of this when logging additional metadata objects. For
240+
> example the below will suppress the `message` property of the metadata
241+
> provided:
242+
>
243+
> ``` js
244+
> logger.log('hello', { message: 'will be hidden' });
245+
> ```
246+
>
247+
> To work around this use the `splat()` format below. e.g.:
248+
>
249+
> ``` js
250+
> logger.log('hello %j', { message: 'will be shown' });
251+
> ```
252+
238253
## Formats
239254
240255
Formats in `winston` can be accessed from `winston.format`. They are

examples/splat-message.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const winston = require('../');
2+
3+
const loggers = {
4+
splat: winston.createLogger({
5+
level: 'info',
6+
format: winston.format.combine(
7+
winston.format.splat(),
8+
winston.format.simple()
9+
),
10+
transports: [new winston.transports.Console()],
11+
}),
12+
simple: winston.createLogger({
13+
level: 'info',
14+
format: winston.format.simple(),
15+
transports: [new winston.transports.Console()],
16+
})
17+
};
18+
19+
const meta = {
20+
subject: 'Hello, World!',
21+
message: 'This message is a unique property separate from implicit merging.',
22+
};
23+
24+
loggers.simple.info('email.message is hidden', meta);
25+
loggers.simple.info('email.message is hidden %j\n', meta);
26+
27+
loggers.splat.info('This is overridden by meta', meta);
28+
loggers.splat.info('email.message is shown %j', meta);

0 commit comments

Comments
 (0)