How do Winston's log streams work?

Viewed 13530

The Winston documentation has a section on streaming logs which says:

Streaming allows you to stream your logs back from your chosen transport.

and gives the following code example:

//
// Start at the end.
//
winston.stream({ start: -1 }).on('log', function(log) {
  console.log(log);
});

My reading of this is that each new log message added would be output to the console. The {start: -1} config tells the stream to start at the end of the file, so only new log entries are output. I expect the following Node script would result in each existing line of the test.log file being output to the console, and then a new object to be output every 500ms thereafter.

var winston = require('winston');
winston.add(winston.transports.File, {
    filename: 'test.log'
});
winston.remove(winston.transports.Console);
winston.stream().on('log', function(log) {
    console.log(log);
});

setInterval(function(){
    winston.log('info', 'help');
}, 500);

I would expect to see something like the following output:

{"level":"info","message":"help","timestamp":"2013-12-10T05:55:15.806Z"}
{"level":"info","message":"help","timestamp":"2013-12-10T05:55:16.307Z"}
{"level":"info","message":"help","timestamp":"2013-12-10T05:55:16.809Z"}
{"level":"info","message":"help","timestamp":"2013-12-10T05:55:17.309Z"}
{"level":"info","message":"help","timestamp":"2013-12-10T05:56:48.316Z"}

What actually occurs is that the logging works as expected with the File transport (the file gets a new log entry every 500ms) but there is no output to the console. The console.log(log) line is never called.

Have I missed something obvious, or misunderstood the purpose of Winston's log streams?

1 Answers
Related