Skip to content

Instantly share code, notes, and snippets.

@avaly
Created November 15, 2018 20:22
Show Gist options
  • Save avaly/527eee1e061accb7e1f446ca105c3094 to your computer and use it in GitHub Desktop.
Save avaly/527eee1e061accb7e1f446ca105c3094 to your computer and use it in GitHub Desktop.
winston-format-bug
const winston = require('winston');
const { combine, printf, splat } = winston.format;
const customFormat = combine(
splat(),
printf((info) => JSON.stringify(info))
);
const logger = winston.createLogger({
transports: [
new winston.transports.Console({
format: customFormat,
}),
new winston.transports.Console({
format: customFormat,
}),
]
});
logger.info('foo', 'bar', 'ham');
logger.info('with interpolated strings: %s and %s', 'bar', 'ham');
const winston = require('winston');
const { combine, printf, splat } = winston.format;
const customFormat = combine(
splat(),
printf((info) => JSON.stringify(info))
);
const logger = winston.createLogger({
format: customFormat,
transports: [
new winston.transports.Console(),
new winston.transports.Console(),
]
});
logger.info('foo', 'bar', 'ham');
logger.info('with interpolated strings: %s and %s', 'bar', 'ham');
@avaly
Copy link
Author

avaly commented Nov 15, 2018

$ node run-with-bug.js 
{"level":"info","message":"foo","meta":["bar","ham"]}
{"level":"info","message":"foo"}
{"level":"info","message":"with interpolated strings: bar and ham"}
{"level":"info","message":"with interpolated strings: bar and ham"}
$ node run-without-bug.js 
{"level":"info","message":"foo","meta":["bar","ham"]}
{"level":"info","message":"foo","meta":["bar","ham"]}
{"level":"info","message":"with interpolated strings: bar and ham"}
{"level":"info","message":"with interpolated strings: bar and ham"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment