Open vjpr opened 12 years ago
Yeah, I can see this being nice.
Do you know how does winston does this? I couldn't get it to work with the recent version and they say they just use util.inspect
, which essentially is equivalent to what logule does.
This sort of works for big circular objects by passing them in separately to the % identifiers at the moment:
var log = require('logule').init(module);
var b = {a:1};
b.b = b; // make it circular
log.info(b);
// prints: 19:15:17 - INFO - { a: 1, b: [Circular] }
log.info("%j", b) // tries to JSON.stringify a circular: throws
But rereading this, ideally what you want is some sort of customized one-level deep loop like this:
var neatObjectify = function (o) {
return Object.keys(o).map(function (k) {
return k + '=' + o[k].toString();
}).join(' ');
};
perhaps also mapping functions to function.name when it exists.
It would be really nice if this was discussed properly with the node team that did util.js
, because otherwise I pretty much have to fork util.format
to get an extra identifier in there I think. Not saying this is an impossibility though, but I probably won't push it to the top of my priorities list for a little while at least. I still like the idea though - so feel free to do it.
(Btw sorry you probably got a random response 5 minutes ago that I did not think through and removed)
Actually, what you want is util.inspect(obj, false, 0)
i.e. depth parameter set to. May be easier than I thought.
Yeah, I think I'll do this now actually. Turns out I can even get repl colors on the objects, just by rewriting util.format
a little and calling util.inspect
with the right parameters.
I'm thinking %0 for a depth zero object scan and %1 for one level one etc (sometimes zero depth is bad if you have small objects/arrays).
Left it out of 2.0 for reasons described in commit there. Might try to bug node core about it.
Would be nice to have the ability to override how an object is printed too.
Sometimes I prefer this:
method=events.batchProcess id=883 params=[object Object] ...
to this:
The Winston logging library prints objects in the first way by default.