flatiron/winston — Issue #74: ability to pass the 'stringify' option to common.log
Author: JoeZ99
Created: 2011-12-06 04:15:25+00:00
State: open

file.js, L92-99

```javascript
File.prototype.log = function (level, msg, meta, callback) {
if (this.silent) {
return callback(null, true);
}

var self = this, output = common.log({
level: level,
message: msg,
meta: meta,
json: this.json,
colorize: this.colorize,
timestamp: this.timestamp
}) + '\n';
```

common.js, L102-120

```javascript
exports.log = function (options) {
var timestampFn = typeof options.timestamp === 'function' ? options.timestamp : exports.timestamp,
timestamp = options.timestamp ? timestampFn() : null,
meta = options.meta ? exports.clone(options.meta) : null,
output;

if (options.json) {
output = meta || {};
output.level = options.level;
output.message = options.message;

if (timestamp) {
output.timestamp = timestamp;
}

return typeof options.stringify === 'function'
? options.stringify(output)
: JSON.stringify(output);
}
```
common.log() expects -among others- the 'stringify' option to be a function to be called when outputting the log msg.

Since common.log() is called with fixed options from within file.js (or console.js), that 'stringify' feature can not be used, and instead the log format is always JSON.stringify({level:'info', msg: 'log message'})

Since common.log already have that option, it could be passed to it through the options passed along when adding the transport.