winston logger not serializing mongodb.ObjectID winston logger not serializing mongodb.ObjectID mongoose mongoose

winston logger not serializing mongodb.ObjectID


What you are looking for is a format specifier most probably.

You can do something like this:

winston.info('%j', new ObjectId());

You can read about format specifiers here http://nodejs.org/api/util.html#util_util_format_format


In the end I wrapped the winston logging methods in a function that just applied the node format utility with the default format to all the arguments. Works a treat so far:

var util = require('util');var winston = require('winston');var fixWinstonParams = function (fn) {    return function () {        for (var i = 0; i < arguments.length; i++) {            arguments[i] = util.format( arguments[i]);        }        return fn.apply(this, arguments);    };};['info', 'error', 'debug', 'warn'].map(function(each){    winston[each] = fixWinstonParams( winston[each])});