Search code examples
node.jsbunyan

LogRotate Bunyan. rotate every 1 minute for testing


I want to try Log Rotate in Bunyan

this is my script

var mongoClient = require('mongodb'),
    bunyan = require('bunyan');


var log = bunyan.createLogger({
    name: 'myapp',
    streams: [
        {
            level:'debug',
            stream: process.stdout
        },
        {
            level: 'info',
            path: 'log/log.log',
            period: '1d',   // daily rotation
            count: 3        // keep 3 back copies
        },
        {
            level: 'error',
            path: 'log/myapp-error.log'

        }
    ]
});
function mockFunction() {
    log.info("----");
    log.info("--log--");
    log.info("----");
    setTimeout(mockFunction, 1000);
}

mockFunction();

How can i Set rotate every 1 minute? for testing

I can choose Hour, day, year,month...https://github.com/trentm/node-bunyan#stream-type-rotating-file

i’ve tried also period: '5ms',, but my file continuing to grow up


Solution

  • You have to add type: 'rotating-file'

    ....{
        type: 'rotating-file',
        level: 'info',
        path: 'log/log.log',
        period: '60000ms',  
        count: 3
    }.....