start upgrading winston

This commit is contained in:
Matteo Pagliazzi 2020-02-20 19:37:31 +01:00
parent 6a483edfe1
commit ed5dfd0228
3 changed files with 115 additions and 27 deletions

85
package-lock.json generated
View file

@ -1070,6 +1070,26 @@
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.0.3.tgz",
"integrity": "sha1-d0Zt5YnNXTyV8TiqeLxWmjy10no="
},
"winston": {
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/winston/-/winston-2.4.4.tgz",
"integrity": "sha512-NBo2Pepn4hK4V01UfcWcDlmiVTs7VTB1h7bgnB0rgP146bYhMxX0ypCz3lBOfNxCO4Zuek7yeT+y/zM1OfMw4Q==",
"requires": {
"async": "~1.0.0",
"colors": "1.0.x",
"cycle": "1.0.x",
"eyes": "0.1.x",
"isstream": "0.1.x",
"stack-trace": "0.0.x"
},
"dependencies": {
"async": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
"integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
}
}
}
}
},
@ -13544,22 +13564,43 @@
"integrity": "sha1-+OGqHuWlPsW/FR/6CXQqatdpeHY="
},
"winston": {
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/winston/-/winston-2.4.4.tgz",
"integrity": "sha512-NBo2Pepn4hK4V01UfcWcDlmiVTs7VTB1h7bgnB0rgP146bYhMxX0ypCz3lBOfNxCO4Zuek7yeT+y/zM1OfMw4Q==",
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/winston/-/winston-3.2.1.tgz",
"integrity": "sha512-zU6vgnS9dAWCEKg/QYigd6cgMVVNwyTzKs81XZtTFuRwJOcDdBg7AU0mXVyNbs7O5RH2zdv+BdNZUlx7mXPuOw==",
"requires": {
"async": "~1.0.0",
"colors": "1.0.x",
"cycle": "1.0.x",
"eyes": "0.1.x",
"isstream": "0.1.x",
"stack-trace": "0.0.x"
"async": "^2.6.1",
"diagnostics": "^1.1.1",
"is-stream": "^1.1.0",
"logform": "^2.1.1",
"one-time": "0.0.4",
"readable-stream": "^3.1.1",
"stack-trace": "0.0.x",
"triple-beam": "^1.3.0",
"winston-transport": "^4.3.0"
},
"dependencies": {
"async": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
"integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz",
"integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==",
"requires": {
"lodash": "^4.17.14"
}
},
"is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
},
"readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
}
}
},
@ -13570,6 +13611,26 @@
"requires": {
"node-loggly-bulk": "^2.0.1",
"winston": "^2.3.1"
},
"dependencies": {
"async": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
"integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
},
"winston": {
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/winston/-/winston-2.4.4.tgz",
"integrity": "sha512-NBo2Pepn4hK4V01UfcWcDlmiVTs7VTB1h7bgnB0rgP146bYhMxX0ypCz3lBOfNxCO4Zuek7yeT+y/zM1OfMw4Q==",
"requires": {
"async": "~1.0.0",
"colors": "1.0.x",
"cycle": "1.0.x",
"eyes": "0.1.x",
"isstream": "0.1.x",
"stack-trace": "0.0.x"
}
}
}
},
"winston-transport": {

View file

@ -69,7 +69,7 @@
"uuid": "^3.4.0",
"validator": "^11.0.0",
"vinyl-buffer": "^1.0.1",
"winston": "^2.4.3",
"winston": "^3.2.1",
"winston-loggly-bulk": "^2.0.2",
"xml2js": "^0.4.23"
},

View file

@ -12,31 +12,58 @@ const IS_TEST = nconf.get('IS_TEST');
const ENABLE_LOGS_IN_TEST = nconf.get('ENABLE_CONSOLE_LOGS_IN_TEST') === 'true';
const ENABLE_LOGS_IN_PROD = nconf.get('ENABLE_CONSOLE_LOGS_IN_PROD') === 'true';
const logger = new winston.Logger();
const logger = winston.createLogger();
if (IS_PROD) {
if (ENABLE_LOGS_IN_PROD) {
logger.add(winston.transports.Console, {
timestamp: true,
colorize: false,
prettyPrint: false,
});
logger.add(winston.transports.Loggly, {
logger.add(new winston.transports.Console({ // for errors
level: 'error', // errors always in JSON
format: winston.format.combine(
winston.format.timestamp(),
winston.format.prettyPrint(),
),
}));
/* logger.add(new winston.transports.Loggly(), {
inputToken: nconf.get('LOGGLY_TOKEN'),
subdomain: nconf.get('LOGGLY_SUBDOMAIN'),
tags: ['Winston-NodeJS'],
json: true,
});
json: true, format.json()
}); */
}
// Do not log anything when testing unless specified
} else if (!IS_TEST || (IS_TEST && ENABLE_LOGS_IN_TEST)) {
logger
.add(winston.transports.Console, {
timestamp: true,
colorize: true,
prettyPrint: true,
});
.add(new winston.transports.Console({
level: 'warn', // warn and errors always in JSON
format: winston.format.combine(
winston.format.timestamp(),
winston.format.colorize(),
winston.format.prettyPrint(),
winston.format(info => {
console.log(info);
})(),
),
}))
.add(new winston.transports.Console({
level: 'info', // the rest as text
format: winston.format.combine(
// Ignores warn and errors
winston.format(info => {
if (info.level === 'error' || info.level === 'warn') {
return false;
}
return info;
})(),
winston.format.timestamp(),
winston.format.colorize(),
winston.format.splat(),
winston.format.simple(),
),
}));
}
// exports a public interface insteaf of accessing directly the logger module