Skip to content

Commit

Permalink
Document the solution to winstonjs#1486. (winstonjs#1554)
Browse files Browse the repository at this point in the history
* [doc] Document the solution to winstonjs#1486.

* [doc] Show both in example.

* [doc] Update the examples.
  • Loading branch information
indexzero authored Dec 26, 2018
1 parent 0aedf8b commit 5e91a1a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ treated as immutable by all code.
- `Symbol.for('message'):` complete string message set by "finalizing
formats": `json`, `logstash`, `printf`, `prettyPrint`, and `simple`.

> **NOTE:** the `message` and `level` properties are considered reserved.
> Please be aware of this when logging additional metadata objects. For
> example the below will suppress the `message` property of the metadata
> provided:
>
> ``` js
> logger.log('hello', { message: 'will be hidden' });
> ```
>
> To work around this use the `splat()` format below. e.g.:
>
> ``` js
> logger.log('hello %j', { message: 'will be shown' });
> ```
## Formats
Formats in `winston` can be accessed from `winston.format`. They are
Expand Down
28 changes: 28 additions & 0 deletions examples/splat-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const winston = require('../');

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

const meta = {
subject: 'Hello, World!',
message: 'This message is a unique property separate from implicit merging.',
};

loggers.simple.info('email.message is hidden', meta);
loggers.simple.info('email.message is hidden %j\n', meta);

loggers.splat.info('This is overridden by meta', meta);
loggers.splat.info('email.message is shown %j', meta);

0 comments on commit 5e91a1a

Please sign in to comment.