Fix streaming for winston
During the upgrade of winston inc3584770f2
a the class extension for streaming was removed. This caused silent crashes. Somehow winston simply called `process.exit(1)` whenever `logger.write()` was called. This is really bad and only easy to debug because of the testing right after upgrading. However, reimplementing the stream interface as it was, didn't work, due to the fact that `logger.write()` is already implemented and causes the mentioned problem. So we extent the object with an `stream` object that implements `write()` for streams and pass that to morgan. So this patch fixes unexpected exiting for streaming towards our logging module. References: https://www.digitalocean.com/community/tutorials/how-to-use-winston-to-log-node-js-applicationsc3584770f2
https://stackoverflow.com/a/28824464 Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
This commit is contained in:
parent
f1367ba270
commit
bdeb053397
2 changed files with 10 additions and 2 deletions
2
app.js
2
app.js
|
@ -53,7 +53,7 @@ if (config.useSSL) {
|
||||||
|
|
||||||
// logger
|
// logger
|
||||||
app.use(morgan('combined', {
|
app.use(morgan('combined', {
|
||||||
'stream': logger
|
'stream': logger.stream
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// socket io
|
// socket io
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
const {createLogger, format, transports} = require('winston')
|
const {createLogger, format, transports} = require('winston')
|
||||||
|
|
||||||
module.exports = createLogger({
|
const logger = createLogger({
|
||||||
level: 'debug',
|
level: 'debug',
|
||||||
format: format.combine(
|
format: format.combine(
|
||||||
format.uncolorize(),
|
format.uncolorize(),
|
||||||
|
@ -17,3 +17,11 @@ module.exports = createLogger({
|
||||||
],
|
],
|
||||||
exitOnError: false
|
exitOnError: false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
logger.stream = {
|
||||||
|
write: function (message, encoding) {
|
||||||
|
logger.info(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = logger
|
||||||
|
|
Loading…
Reference in a new issue