Skip to content

Commit bdeb053

Browse files
committed
Fix streaming for winston
During the upgrade of winston in c358477 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-applications c358477 https://stackoverflow.com/a/28824464 Signed-off-by: Sheogorath <[email protected]>
1 parent f1367ba commit bdeb053

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if (config.useSSL) {
5353

5454
// logger
5555
app.use(morgan('combined', {
56-
'stream': logger
56+
'stream': logger.stream
5757
}))
5858

5959
// socket io

lib/logger.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22
const {createLogger, format, transports} = require('winston')
33

4-
module.exports = createLogger({
4+
const logger = createLogger({
55
level: 'debug',
66
format: format.combine(
77
format.uncolorize(),
@@ -17,3 +17,11 @@ module.exports = createLogger({
1717
],
1818
exitOnError: false
1919
})
20+
21+
logger.stream = {
22+
write: function (message, encoding) {
23+
logger.info(message)
24+
}
25+
}
26+
27+
module.exports = logger

0 commit comments

Comments
 (0)