Skip to content

Commit 9d01a47

Browse files
author
Matt Berther
committed
update query to search inside archive files
1 parent 0f1ae73 commit 9d01a47

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

daily-rotate-file.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,16 @@ DailyRotateFile.prototype.query = function (options, callback) {
190190
var logFile = path.join(self.dirname, file);
191191
var buff = '';
192192

193-
var stream = fs.createReadStream(logFile, {
194-
encoding: 'utf8'
195-
});
193+
var stream;
194+
195+
if (file.endsWith('.gz')) {
196+
stream = new PassThrough();
197+
fs.createReadStream(logFile).pipe(zlib.createGunzip()).pipe(stream);
198+
} else {
199+
stream = fs.createReadStream(logFile, {
200+
encoding: 'utf8'
201+
});
202+
}
196203

197204
stream.on('error', function (err) {
198205
if (stream.readable) {
@@ -215,7 +222,7 @@ DailyRotateFile.prototype.query = function (options, callback) {
215222
buff = data[l];
216223
});
217224

218-
stream.on('close', function () {
225+
stream.on('end', function () {
219226
if (buff) {
220227
add(buff, true);
221228
}

test/transport-tests.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ describe('winston/transports/daily-rotate-file', function () {
214214

215215
this.transport.close();
216216
});
217+
218+
it('should search within archived files', function (done) {
219+
var opts = Object.assign({}, options);
220+
opts.zippedArchive = true;
221+
opts.maxSize = '1k';
222+
223+
this.transport = new DailyRotateFile(opts);
224+
225+
sendLogItem(this.transport, 'info', randomString(1056));
226+
sendLogItem(this.transport, 'info', randomString(1056));
227+
228+
var self = this;
229+
230+
self.transport.on('archive', function () {
231+
self.transport.query(function (err, results) {
232+
expect(results).to.not.be.null;
233+
expect(results.length).to.equal(2);
234+
done();
235+
});
236+
});
237+
this.transport.close();
238+
});
217239
});
218240
});
219241
});

0 commit comments

Comments
 (0)