Skip to content

Commit 57a7cb8

Browse files
committed
Fixed winston transport output
1 parent a593ff3 commit 57a7cb8

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

cf-nodejs-logging-support-winston/winston-transport.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ const CfNodejsLoggingSupportLogger = class CfNodejsLoggingSupportLogger extends
99
this.logMessage = options.logMessage;
1010
}
1111

12-
log(info) {
12+
log(info, callback) {
13+
setImmediate(() => {
14+
this.emit('logged',info);
15+
});
16+
1317
if (info[SPLAT]) {
1418
this.logMessage.apply(this, [info.level, info.message, ...info[SPLAT]]);
1519
} else {
1620
this.logMessage(info.level, info.message);
1721
}
22+
23+
callback();
1824
}
1925
};
2026

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample/winston-sample/package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample/winston-sample/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "web.js",
66
"license": "Apache-2.0",
77
"scripts": {
8-
"test": "echo \"Error: no test specified\" && exit 1"
8+
"test": "echo \"Error: no test specified\" && exit 1",
9+
"start": "node web.js"
910
},
1011
"keywords": [
1112
"example",

sample/winston-sample/web.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var logger = winston.createLogger({
1111

1212
app.get('/', function (req, res) {
1313
res.send('Hello World');
14+
logger.log("info", "Received request");
1415
});
1516

1617
app.listen(3000);

test/test-winston.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ describe('Test winston-transport.js', function () {
2929
info.level = "error";
3030
info.message = "test"
3131

32-
transport.log(info);
32+
var called = false;
33+
var callback = () => {called = true}
34+
35+
transport.log(info, callback);
3336

3437
catchedArgs.length.should.equal(2);
3538
catchedArgs[0].should.equal("error");
3639
catchedArgs[1].should.equal("test");
40+
called.should.equal(true)
3741
});
3842

3943
it('Test log method (message with additional variables)', function () {
@@ -43,13 +47,17 @@ describe('Test winston-transport.js', function () {
4347
info.message = "test %d %s"
4448
info[SPLAT] = [42, "abc"]
4549

46-
transport.log(info);
50+
var called = false;
51+
var callback = () => {called = true}
52+
53+
transport.log(info, callback);
4754

4855
catchedArgs.length.should.equal(4);
4956
catchedArgs[0].should.equal("error");
5057
catchedArgs[1].should.equal("test %d %s");
5158
catchedArgs[2].should.equal(42);
5259
catchedArgs[3].should.equal("abc");
60+
called.should.equal(true)
5361
});
5462
});
5563

0 commit comments

Comments
 (0)