xmilliard/node-streamlogger — comment on commit edb7717b0ec55163b6cfd6302e02a93458e09ea8
File:  line 0
By xmilliard:

Hello Andrew,

I'll try to explain myself, sorry for the obscure patch ;-)

if i add a specific format in your example (simple-example.js) :

~~~ {.javascript}
logger.format = function(message,levelName) {
if (levelName == 'warn')
return "Custom message: " + message;
else
return false; //Use the default format
}

~~~

log.warn("my message') will add 'false' in my log and not the message itself, because you test the presence of a 'format' property, not value returned by the 'format' function.

A more correct and simple patch may be :

~~~ {.javascript}
var outMessage = false;
// if specific format is found
if(this.format) {
// try to use it
outMessage = this.format(message, levelName);
}
// if specific format doesn't return something
// fall back to default
if(!outMessage) {
outMessage = (new Date).toUTCString() + ' - ' + levelName + ': ' + message;
}
~~~