stop logs print in lower levels with rotating-files #394

Closed
Turok21 opened this Issue Apr 15, 2016 · 2 comments

Projects

None yet

2 participants

@Turok21
Turok21 commented Apr 15, 2016 edited

Hi,

I'm trying to stop logs be print in lower level, but I don't find a solution for it :
I already see issues : #334 #320 #339 #305 and some others,
And also inspect https://github.com/trentm/node-bunyan/blob/master/examples/specific-level-streams.js

But i don't reach to do specific level with "rotating-file"
I am stuck with this and don't reach to found a solution

Here my configuration file :

var NODE_ENV = process.env.NODE_ENV || 'local';
var config   = require('../../config.json')[NODE_ENV];
var path     = config.logs.path; // like "./utils/logs/"

var configLogger = {
    name    : "xxxxxxxx",
    streams : []
};
/************************* ***************************/
/***************    STREAM IN FILES   ****************/
    var levels = ['debug', 'info', 'warn', 'error', 'trace'];
    var _logLevel = function (level) {
        return {
            type   : 'rotating-file',
            period : '1w',
            count  : 52,
            level  : level,
            path   : path + 'application-' + level + '.log'
        };
    };
    levels.forEach(function (level) {
        configLogger.streams.push(_logLevel(level));
    }, this);
/******************  END    FILES  *******************/

So at the end,
configLogger likes :

{ name: 'xxxxxxxx',
  streams: 
   [ { type: 'rotating-file',
       period: '1w',
       count: 52,
       level: 'debug',
       path: './utils/logs/apps-debug.log' },
     { type: 'rotating-file',
       period: '1w',
       count: 52,
       level: 'info',
       path: './utils/logs/apps-info.log' },
     { type: 'rotating-file',
       period: '1w',
       count: 52,
       level: 'warn',
       path: './utils/logs/apps-warn.log' },
     { type: 'rotating-file',
       period: '1w',
       count: 52,
       level: 'error',
       path: './utils/logs/apps-error.log' },
     { type: 'rotating-file',
       period: '1w',
       count: 52,
       level: 'trace',
       path: './utils/logs/apps-trace.log' } ] }

and I configLogger.level = "trace"; module.exports = require('bunyan').createLogger(configLogger);

I'm here asking your help using bunyan ;)

Thanks for helping

@trentm trentm added a commit that referenced this issue Apr 21, 2016
@trentm Add example for #394 4744d63
@trentm
Owner
trentm commented Apr 21, 2016

@Turok21 It isn't easy or obvious how to use two separate specific streams here. I wrote an example that works for this: https://github.com/trentm/node-bunyan/blob/master/examples/rot-specific-levels.js
Hope that helps.

@trentm trentm closed this Apr 21, 2016
@Turok21
Turok21 commented Apr 21, 2016

Hi,
This work perfectly,

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment