Permalink
Browse files

[minor] Add `options.decycle` option to transports.

  • Loading branch information...
1 parent 6cb1d48 commit 691f03f3051db67233ef05423e83ad5eac032283 @coderarity coderarity committed May 6, 2012
View
@@ -456,6 +456,7 @@ The Console transport takes two simple options:
* __silent:__ Boolean flag indicating whether to suppress output (default false).
* __colorize:__ Boolean flag indicating if we should colorize output (default false).
* __timestamp:__ Boolean flag indicating if we should prepend output with timestamps (default false). If function is specified, its return value will be used instead of timestamps.
+* __decycle:__ Boolean flag indicating if `meta` should be [decycled](https://github.com/douglascrockford/JSON-js).
*Metadata:* Logged via util.inspect(meta);
@@ -475,6 +476,7 @@ The File transport should really be the 'Stream' transport since it will accept
* __maxFiles:__ Limit the number of files created when the size of the logfile is exceeded.
* __stream:__ The WriteableStream to write output to.
* __json:__ If true, messages will be logged as JSON (default true).
+* __decycle:__ Boolean flag indicating if `meta` should be [decycled](https://github.com/douglascrockford/JSON-js).
*Metadata:* Logged via util.inspect(meta);
@@ -491,6 +493,7 @@ The Loggly transport is based on [Nodejitsu's][5] [node-loggly][6] implementatio
* __inputName:__ The name of the input this instance should log to.
* __inputToken:__ The input token of the input this instance should log to.
* __json:__ If true, messages will be sent to Loggly as JSON.
+* __decycle:__ Boolean flag indicating if `meta` should be [decycled](https://github.com/douglascrockford/JSON-js).
*Metadata:* Logged in suggested [Loggly format][2]
View
@@ -109,9 +109,19 @@ exports.clone = function (obj) {
exports.log = function (options) {
var timestampFn = typeof options.timestamp === 'function' ? options.timestamp : exports.timestamp,
timestamp = options.timestamp ? timestampFn() : null,
- meta = options.meta ? exports.clone(cycle.decycle(options.meta)) : null,
+ meta,
output;
+ if (options.decycle && options.meta) {
+ meta = cycle.decycle(options.meta);
+ }
+ else if (options.meta) {
+ meta = exports.clone(options.meta);
+ }
+ else {
+ meta = null;
+ }
+
//
// raw mode is intended for outputing winston as streaming JSON to STDOUT
//
@@ -66,6 +66,7 @@ Console.prototype.log = function (level, msg, meta, callback) {
level: level,
message: msg,
meta: meta,
+ decycle: this.decycle,
stringify: this.stringify,
timestamp: this.timestamp,
raw: this.raw
@@ -83,4 +84,5 @@ Console.prototype.log = function (level, msg, meta, callback) {
//
self.emit('logged');
callback(null, true);
-};
+};
+
@@ -67,11 +67,20 @@ Couchdb.prototype.log = function (level, msg, meta, callback) {
}
var self = this,
- meta = cycle.decycle(meta),
- message = common.clone(meta || {}),
options,
+ message,
req;
+ if (this.decycle && meta) {
+ message = meta = cycle.decycle(meta);
+ }
+ else if (meta) {
+ message = common.clone(meta);
+ }
+ else {
+ message = {};
+ }
+
message.level = level;
message.message = msg;
@@ -93,6 +93,7 @@ File.prototype.log = function (level, msg, meta, callback) {
level: level,
message: msg,
meta: meta,
+ decycle: this.decycle,
json: this.json,
colorize: this.colorize,
timestamp: this.timestamp
@@ -329,4 +330,5 @@ File.prototype._lazyDrain = function () {
self.emit('logged');
});
}
-};
+};
+
@@ -95,7 +95,18 @@ Loggly.prototype.log = function (level, msg, meta, callback) {
}
var self = this,
- message = common.clone(meta || {});
+ message;
+
+ if (options.decycle && meta) {
+ message = meta = cycle.decycle(options.meta);
+ }
+ else if (meta) {
+ message = common.clone(options.meta);
+ }
+ else {
+ meta = {};
+ }
+
message.level = level;
message.message = msg;
@@ -158,4 +169,5 @@ Loggly.prototype.flush = function () {
//
self.logBuffer.length = 0;
});
-};
+};
+
@@ -18,10 +18,11 @@ var events = require('events'),
var Transport = exports.Transport = function (options) {
events.EventEmitter.call(this);
- options = options || {};
- this.level = options.level || 'info';
- this.silent = options.silent || false;
- this.raw = options.raw || false;
+ options = options || {};
+ this.level = options.level || 'info';
+ this.silent = options.silent || false;
+ this.raw = options.raw || false;
+ this.decycle = options.decycle || false;
this.handleExceptions = options.handleExceptions || false;
};
@@ -56,4 +57,5 @@ Transport.prototype.logException = function (msg, meta, callback) {
this.once('logged', onLogged);
this.once('error', onError);
this.log('error', msg, meta, function () { });
-};
+};
+
@@ -68,11 +68,20 @@ Webhook.prototype.log = function (level, msg, meta, callback) {
}
var self = this,
- meta = cycle.decycle(meta),
- message = common.clone(meta),
options,
+ message,
req;
+ if (this.decycle && meta) {
+ message = meta = cycle.decycle(meta);
+ }
+ else if (meta) {
+ message = common.clone(meta);
+ }
+ else {
+ message = {};
+ }
+
message.level = level;
message.message = msg;
@@ -22,4 +22,5 @@ logger.handleExceptions();
setTimeout(function () {
throw new Error('OH NOES! It failed!');
-}, 1000);
+}, 1000);
+
View
@@ -180,7 +180,9 @@ helpers.testLevels = function (levels, transport, assertMsg, assertFn) {
var circmetadatatest = {
topic: function () {
+ transport.decycle = true;
transport.log('info', 'test message', circmetadata, this.callback.bind(this, null));
+ transport.decycle = false;
}
};

0 comments on commit 691f03f

Please sign in to comment.