5

Bunyan-node logs are printed (to stdout) with numeric log levels, as defined in the bunyan doc (https://github.com/trentm/node-bunyan#levels )

{ ... , level: 10, .... }

Is it possible to print them with the actual value, in this case-

{ ... , level: "trace", .... }

?

Mattan Bitner
  • 1,463
  • 3
  • 14
  • 29
  • If you insist not to use number, how about define constant like TRACE = 10 and use it ( it will give level: TRACE)? – Ediruth Jul 20 '16 at 11:03

2 Answers2

0

I don't think it is possible using bunyan, as per the document level in core-fields.

level: Required. Integer. Added by Bunyan. Cannot be overridden. See the "Levels" section.

https://github.com/trentm/node-bunyan#core-fields

Avi
  • 1,424
  • 1
  • 11
  • 32
-3

Short answer: Yes

See how they got it implemented in their test case.

var bunyan = require('../lib/bunyan');
var log1 = bunyan.createLogger({
    name: 'log1',
    streams: [
        {
            path: __dirname + '/level.test.log1.log',
            level: 'info' /* Using word */
        }
    ]
});

Reference:
https://github.com/trentm/node-bunyan/blob/master/test/level.test.js

I had a quick look at their source code and it seems like you could also possibly get away with something like bunyan.levelFromName.fatal or bunyan.levelFromName["fatal"] to get the respective debugging value too.

See:
https://github.com/trentm/node-bunyan/blob/master/lib/bunyan.js#L253-L269

Also note: The last few lines of the code.

module.exports.levelFromName = levelFromName;

Samuel Toh
  • 18,006
  • 3
  • 24
  • 39