Merge pull request #23 from davepacheco/master

fix test failures (for bunyan CLI multiple-log record merging)
This commit is contained in:
Trent Mick 2012-06-21 14:02:38 -07:00
commit 0047bc060f
3 changed files with 14 additions and 2 deletions

View file

@ -206,7 +206,7 @@ function emitNextRecord(opts, stylize)
} }
} }
if (!ready) { if (!ready || minfile === undefined) {
for (ofile in streams) { for (ofile in streams) {
if (!streams[ofile].stream || streams[ofile].done) if (!streams[ofile].stream || streams[ofile].done)
continue; continue;
@ -703,6 +703,7 @@ function processFile(file, opts, stylize, callback) {
streams[file].stream = stream; streams[file].stream = stream;
stream.on('error', function (err) { stream.on('error', function (err) {
streams[file].done = true;
callback(err); callback(err);
}); });
@ -726,11 +727,13 @@ function processFile(file, opts, stylize, callback) {
}); });
stream.on('end', function () { stream.on('end', function () {
streams[file].done = true;
if (leftover) { if (leftover) {
handleLogLine(file, leftover, opts, stylize); handleLogLine(file, leftover, opts, stylize);
leftover = ''; leftover = '';
} else {
emitNextRecord(opts, stylize);
} }
streams[file].done = true;
callback(); callback();
}); });
} }

4
test/corpus/log1.log Normal file
View file

@ -0,0 +1,4 @@
{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T16:57:55.586Z","v":0}
{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.339Z","v":0}
{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.404Z","v":0}
{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.404Z","v":0}

5
test/corpus/log2.log Normal file
View file

@ -0,0 +1,5 @@
{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T16:58:55.586Z","v":0}
{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:01:49.339Z","v":0}
{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:47.404Z","v":0}
{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:57.404Z","v":0}
{"name":"agent2","pid":76156,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:08:01.105Z","v":0}