javascript - winston.js info method not passing metadata -


when i'm passing metadata through winston shortcut winston.info method isn't passing along metadata.

var winston = require('winston');  winston.info("winston metadata", {cluster: "bar"}); winston.log("info", "winston metadata", {cluster: "baz"}); 

output:

info: winston metadata info: winston metadata cluster=baz 

i'd expect both calls print out metadata?

digging through winston code looks dynamically generates shortcut functions each level ('info', 'debug', 'error'), , tries handle additional metadata arguments:

// // ### function setlevels (target, past, current) // #### @target {object} object on set levels. // #### @past {object} previous levels set on target. // #### @current {object} current levels set on target. // create functions on target objects each level // in current.levels. if past defined, remove functions // each of levels. // exports.setlevels = function (target, past, current, isdefault) {   if (past) {     object.keys(past).foreach(function (level) {       delete target[level];     });   }    target.levels = current || config.npm.levels;   if (target.padlevels) {     target.levellength = exports.longestelement(object.keys(target.levels));   }    //   //  define prototype methods each log level   //  e.g. target.log('info', msg) <=> target.info(msg)   //   object.keys(target.levels).foreach(function (level) {     target[level] = function (msg) {       var args = array.prototype.slice.call(arguments, 1),           callback = args.pop(),           ltype = typeof callback,           meta = args.length ? args : null;        if (ltype !== 'function') {         if (meta && ltype !== 'undefined') {           meta.push(callback);         }          callback = null;       }        if (meta) {         meta = (meta.length <= 1 && meta.shift()) || meta;         return callback           ? target.log(level, msg, meta, callback)           : target.log(level, msg, meta)       }        return callback         ? target.log(level, msg, callback)         : target.log(level, msg)     };   });    return target; }; 

i think due regression in v0.7.1 of winston.

given input:

var winston = require("winston");  var logger = new winston.logger({     levels: {         debug: 0,         info: 1,         warn: 2,         error: 3     },   transports: [       new winston.transports.console({           level: 'debug',           colorize: true       })   ] });  console.log('winston version: ' + winston.version);  console.log('\nproxy methods\n'); logger.info("hello world"); logger.warn("hello world", { winston: {     version: winston.version }});  console.log('\ndirect access methods\n') logger.log('info', "hello world"); logger.log('warn', "hello world", { version: winston.version }); 

you following output

winston version: 0.6.2  proxy methods  info: hello world warn: hello world version=0.6.2  direct access methods  info: hello world warn: hello world version=0.6.2 

versus:

winston version: 0.7.1  proxy methods  info: hello world warn: hello world  direct access methods  info: hello world warn: hello world version=0.7.1 

i've updated https://github.com/flatiron/winston/pull/246 reflect regression, before accepting pr.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -