File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -445,7 +445,7 @@ DailyRotateFile.prototype.open = function (callback) {
445
445
callback ( true ) ;
446
446
return this . _createStream ( ) ;
447
447
}
448
- this . _archive = this . zippedArchive ? this . _stream . path : false ;
448
+
449
449
//
450
450
// Otherwise we have a valid (and ready) stream.
451
451
//
@@ -519,13 +519,14 @@ DailyRotateFile.prototype._createStream = function () {
519
519
520
520
( function checkFile ( target ) {
521
521
var fullname = path . join ( self . dirname , target ) ;
522
-
523
522
//
524
523
// Creates the `WriteStream` and then flushes any
525
524
// buffered messages.
526
525
//
527
526
function createAndFlush ( size ) {
528
527
if ( self . _stream ) {
528
+ self . _archive = self . zippedArchive ? self . _stream . path : false ;
529
+
529
530
self . _stream . end ( ) ;
530
531
self . _stream . destroySoon ( ) ;
531
532
}
Original file line number Diff line number Diff line change @@ -686,6 +686,35 @@ describe('winston/transports/daily-rotate-file', function () {
686
686
tk . reset ( ) ;
687
687
} ) ;
688
688
689
+ it ( 'should compress logfile even if there is only one log message' , function ( done ) {
690
+ var self = this ;
691
+
692
+ transport . log ( 'error' , 'test message' , { } , function ( err ) {
693
+ if ( err ) {
694
+ done ( err ) ;
695
+ }
696
+
697
+ var filesCreated = fs . readdirSync ( rotationLogPath ) ;
698
+ expect ( filesCreated . length ) . to . eql ( 1 ) ;
699
+ expect ( filesCreated ) . to . include ( pattern . oldfile ) ;
700
+ self . time = new Date ( pattern . end ) ;
701
+ tk . travel ( self . time ) ;
702
+ transport . log ( 'error' , '2nd test message' , { } , function ( err ) {
703
+ if ( err ) {
704
+ done ( err ) ;
705
+ }
706
+
707
+ filesCreated = fs . readdirSync ( rotationLogPath ) ;
708
+ expect ( filesCreated . length ) . to . eql ( 2 ) ;
709
+ expect ( filesCreated ) . to . include ( pattern . newfile ) ;
710
+ expect ( filesCreated ) . to . include ( pattern . oldfile + '.gz' ) ;
711
+ transport . close ( ) ;
712
+
713
+ done ( ) ;
714
+ } ) ;
715
+ } ) ;
716
+ } ) ;
717
+
689
718
it ( 'should compress logfile without adding count to file extension if there are no files with the same name' , function ( done ) {
690
719
var self = this ;
691
720
You can’t perform that action at this time.
0 commit comments