Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
logger: always use JSON to log, don't try to prettify
Browse files Browse the repository at this point in the history
Winston always pretty-print JSON. Workaround that. We loose the color.
People should use jq if they want to pretty print logs.
  • Loading branch information
vincentbernat committed Sep 2, 2019
1 parent 0630ce9 commit 9a5e1d1
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@ var _ = require('lodash'),
expressWinston = require('express-winston'),
config = require('./config');

var transports = [
new winston.transports.Console({
prettyPrint: false,
colorize: true,
silent: false,
timestamp: true,
handleExceptions: true,
level: config.get('log:level')
})
var commonLogOptions = {
prettyPrint: false,
timestamp: true,
handleExceptions: true,
level: config.get('log:level'),
json: true,
stringify: function(obj) { return JSON.stringify(obj); }
},
transports = [
new winston.transports.Console(_.merge({
silent: false
}, commonLogOptions))
];

if (config.get('log:file')) {
transports.push(
new winston.transports.File({
prettyPrint: false,
colorize: false,
timestamp: true,
handleExceptions: true,
level: config.get('log:level'),
new winston.transports.File(_.merge({
filename: config.get('log:file')
})
}, commonLogOptions))
);
}

Expand Down

0 comments on commit 9a5e1d1

Please sign in to comment.