Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

Turok21 opened this issue Apr 15, 2016 · 2 comments

Comments

@Turok21
Copy link

Turok21 commented Apr 15, 2016

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
Copy link
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.

@Turok21
Copy link
Author

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
Projects
None yet
Development

No branches or pull requests

2 participants