Rcomian / bunyan-rotating-file-stream

Is an endpoint for bunyan that lets you control how much disk space logs take.
Other
29 stars 15 forks source link

Does not write logs #14

Closed ilkerfindik closed 7 years ago

ilkerfindik commented 7 years ago

This is the setup code I am using

var traceStreamerRotatedByLength = {
        type:'raw',
        stream:new RotatingFileStream({
            path: './log/ROTATINGFILESTREAM_'+applicationName + dateStringOrEmptyString + '.info.log',
            level: debugLogLevel,
            period: '60000ms',      // daily rotation
            totalFiles: 1000,       // keep 10 back copies
            threshold: '100m',      // Rotate log files larger than 10 megabytes
            totalSize: '8g',        // Don't keep more than 20mb of archived log files
            rotateExisting: true,   // Give ourselves a clean file when we start up, based on period
            gzip: true              // Compress the archive log files to save space
        })
    };

var errorStreamerRotatedByLength = {
        type:'raw',
        stream:new RotatingFileStream({
            path: './log/ROTATINGFILESTREAM_'+applicationName + dateStringOrEmptyString + '.errors.log',
            level: 'error',
            period: '60000ms',              // daily rotation
            totalFiles: 1000,       // keep 10 back copies
            threshold: '100m',      // Rotate log files larger than 10 megabytes
            totalSize: '8g',        // Don't keep more than 20mb of archived log files
            rotateExisting: true,   // Give ourselves a clean file when we start up, based on period
            gzip: true              // Compress the archive log files to save space
        })
    };

var myLogger = bunyan.createLogger({
        name: applicationName,
        serializers: bunyan.stdSerializers,
        streams: [
            traceStreamerRotatedByLength,
            errorStreamerRotatedByLength
        ]
    });

myLogger.log = function(whatToLog){
        console.log(whatToLog);
        if(traceLevelLogged){
            return myLogger.trace({traceData:whatToLog});
        }
    };

This creates zip files but all of them contain a single (empty) file and the sizes of zip files are always the same.

Rcomian commented 7 years ago

Apologies for the time getting back to you. Your reproduction was very helpful, thank you.

It turns out the level option on the streams needs to be moved up a level. It's not a property of the RotatingFileStream, it a property at the same level as type: 'raw'.

To set up the info stream it would be something like this instead:

var traceStreamerRotatedByLength = {
        type:'raw',
        level: debugLogLevel,
        stream: new RotatingFileStream({
            path: './log/ROTATINGFILESTREAM_'+applicationName + dateStringOrEmptyString + '.info.log',
            period: '60000ms',      // daily rotation
            totalFiles: 1000,       // keep 10 back copies
            threshold: '100m',      // Rotate log files larger than 10 megabytes
            totalSize: '8g',        // Don't keep more than 20mb of archived log files
            rotateExisting: true,   // Give ourselves a clean file when we start up, based on period
            gzip: true              // Compress the archive log files to save space
        })
    };

Once that's in place, filtering the different logs to the different log streams should work fine.

Cheers