Skip to content

Commit

Permalink
Add depth options for meta pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicMahieu authored and indexzero committed Dec 30, 2014
1 parent d5e6297 commit 0a848fa
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 37 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ The Console transport takes a few 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.
* __prettyPrint:__ Boolean flag indicating if we should `util.inspect` the meta (default false).
* __depth__ Numeric indicating how many times to recurse while formatting the object with `util.inspect` (only used with `prettyPrint: true`) (default null, unlimited)

*Metadata:* Logged via util.inspect(meta);

Expand All @@ -626,6 +628,7 @@ The File transport should really be the 'Stream' transport since it will accept
* __stream:__ The WriteableStream to write output to.
* __json:__ If true, messages will be logged as JSON (default true).
* __prettyPrint:__ If true, additional JSON metadata objects that are added to logging string messages will be displayed as a JSON string representation.
* __depth__ Numeric indicating how many times to recurse while formatting the object with `util.inspect` (only used with `prettyPrint: true`) (default null, unlimited)
* __logstash:__ If true, messages will be logged as JSON and formatted for logstash (default false).

*Metadata:* Logged via util.inspect(meta);
Expand All @@ -637,7 +640,7 @@ The File transport should really be the 'Stream' transport since it will accept

The Daily Rotate File transport lets you rotate log files based on time.

In addition to the options accepted by the File transport, the Daily Rotate File Transport also accepts the following option.
In addition to the options accepted by the File transport, the Daily Rotate File Transport also accepts the following option.

* __datePattern:__ Defines rolling time of a log file and suffix appended to the file. Following meta characters can be used: `yy`, `yyyy`, `M`, `MM`, `d`, `dd`, `H`, `HH`, `m`, `mm`. The default pattern is `'.yyyy-MM-dd'`. Rotation time of the log file will be equal to the smallest given time token timespan, so `'.yyyy-MM-ddTHH'` will rotate logfile every hour. You can not rotate files more frequent then every minute.

Expand Down
58 changes: 31 additions & 27 deletions docs/transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ There are several [core transports](#winston-core) included in `winston`, which
* [MongoDB](#mongodb-transport)
* [Redis](#redis-transport)
* [Riak](#riak-transport)

* **[Additional Transports](#additional-transports)**
* [SimpleDB](#simpledb-transport)
* [Mail](#mail-transport)
Expand All @@ -26,7 +26,7 @@ There are several [core transports](#winston-core) included in `winston`, which

## Winston Core

There are several core transports included in `winston`, which leverage the built-in networking and file I/O offered by node.js core.
There are several core transports included in `winston`, which leverage the built-in networking and file I/O offered by node.js core.

* [Console](#console-transport)
* [File](#file-transport)
Expand All @@ -48,6 +48,8 @@ The Console transport takes four simple options:
* __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.
* __json:__ Boolean flag indicating whether or not the output should be JSON. If true, will log out multi-line JSON objects. (default false)
* __stringify:__ Boolean flag indiciating if the output should be passed through JSON.stringify, resulting in single-line output. Most useful when used in conjunction with the json flag. (default false)
* __prettyPrint:__ Boolean flag indicating if we should `util.inspect` the meta (default false).
* __depth__ Numeric indicating how many times to recurse while formatting the object with `util.inspect` (only used with `prettyPrint: true`) (default null, unlimited)

*Metadata:* Logged via util.inspect(meta);

Expand All @@ -69,6 +71,8 @@ The File transport should really be the 'Stream' transport since it will accept
* __stream:__ The WriteableStream to write output to.
* __json:__ If true, messages will be logged as JSON (default true).
* __eol:__ string indicating the end-of-live characters to use (default to `\n`).
* __prettyPrint:__ Boolean flag indicating if we should `util.inspect` the meta (default false).
* __depth__ Numeric indicating how many times to recurse while formatting the object with `util.inspect` (only used with `prettyPrint: true`) (default null, unlimited)

*Metadata:* Logged via util.inspect(meta);

Expand Down Expand Up @@ -107,7 +111,7 @@ The `Http` transport is a generic way to log, query, and stream logs from an arb

* __host:__ (Default: **localhost**) Remote host of the HTTP logging endpoint
* __port:__ (Default: **80 or 443**) Remote port of the HTTP logging endpoint
* __path:__ (Default: **/**) Remote URI of the HTTP logging endpoint
* __path:__ (Default: **/**) Remote URI of the HTTP logging endpoint
* __auth:__ (Default: **None**) An object representing the `username` and `password` for HTTP Basic Auth
* __ssl:__ (Default: **false**) Value indicating if we should us HTTPS

Expand All @@ -133,7 +137,7 @@ The `Couchdb` will place your logs in a remote CouchDB database. It will also cr

* __host:__ (Default: **localhost**) Remote host of the HTTP logging endpoint
* __port:__ (Default: **5984**) Remote port of the HTTP logging endpoint
* __db:__ (Default: **winston**) Remote URI of the HTTP logging endpoint
* __db:__ (Default: **winston**) Remote URI of the HTTP logging endpoint
* __auth:__ (Default: **None**) An object representing the `username` and `password` for HTTP Basic Auth
* __ssl:__ (Default: **false**) Value indicating if we should us HTTPS

Expand All @@ -153,7 +157,7 @@ In addition to these, the Redis transport also accepts the following options.

* __length:__ (Default **200**) Number of log messages to store.
* __container:__ (Default **winston**) Name of the Redis container you wish your logs to be in.
* __channel:__ (Default **None**) Name of the Redis channel to stream logs from.
* __channel:__ (Default **None**) Name of the Redis channel to stream logs from.

*Metadata:* Logged as JSON literal in Redis

Expand Down Expand Up @@ -321,7 +325,7 @@ The Graylog2 transport connects to a Graylog2 server over UDP using the followin
- __hostname__: the name of this host (default: os.hostname())
- __facility__: the facility for these log messages (default: "Node.js")
- __bufferSize__: max UDP packet size, should never exceed the MTU of your system (default: 1400)


### Cassandra Transport

Expand Down Expand Up @@ -351,28 +355,28 @@ Array of strings containing the hosts, for example `['host1', 'host2']` (require
``` bash
$ npm search winston
(...)
winston-amon Winston transport for Amon logging =zoramite
winston-amqp An AMQP transport for winston =kr1sp1n
winston-cassandra A Cassandra transport for winston =jorgebay
winston-couchdb a couchdb transport for winston =alz
winston-express Express middleware to let you use winston from the browser. =regality
winston-graylog2 A graylog2 transport for winston =smithclay
winston-hbase A HBase transport for winston =ddude
winston-loggly A Loggly transport for winston =indexzero
winston-mail A mail transport for winston =wavded
winston-mail2 A mail transport for winston =ivolo
winston-mongodb A MongoDB transport for winston =indexzero
winston-nodemail A mail transport for winston =reinpk
winston-nssocket nssocket transport for winston =mmalecki
winston-papertrail A Papertrail transport for winston =kenperkins
winston-redis A fixed-length Redis transport for winston =indexzero
winston-riak A Riak transport for winston =indexzero
winston-scribe A scribe transport for winston =wnoronha
winston-simpledb A Winston transport for Amazon SimpleDB =chilts
winston-skywriter A Windows Azure table storage transport for winston =pofallon
winston-amon Winston transport for Amon logging =zoramite
winston-amqp An AMQP transport for winston =kr1sp1n
winston-cassandra A Cassandra transport for winston =jorgebay
winston-couchdb a couchdb transport for winston =alz
winston-express Express middleware to let you use winston from the browser. =regality
winston-graylog2 A graylog2 transport for winston =smithclay
winston-hbase A HBase transport for winston =ddude
winston-loggly A Loggly transport for winston =indexzero
winston-mail A mail transport for winston =wavded
winston-mail2 A mail transport for winston =ivolo
winston-mongodb A MongoDB transport for winston =indexzero
winston-nodemail A mail transport for winston =reinpk
winston-nssocket nssocket transport for winston =mmalecki
winston-papertrail A Papertrail transport for winston =kenperkins
winston-redis A fixed-length Redis transport for winston =indexzero
winston-riak A Riak transport for winston =indexzero
winston-scribe A scribe transport for winston =wnoronha
winston-simpledb A Winston transport for Amazon SimpleDB =chilts
winston-skywriter A Windows Azure table storage transport for winston =pofallon
winston-sns A Simple Notification System Transport for winston =jesseditson
winston-syslog A syslog transport for winston =indexzero
winston-syslog-ain2 An ain2 based syslog transport for winston =lamtha
winston-syslog A syslog transport for winston =indexzero
winston-syslog-ain2 An ain2 based syslog transport for winston =lamtha
winston-winlog Windows Event Log logger for Winston =jfromaniello
winston-zmq A 0MQ transport for winston =dhendo
winston-growl A growl transport for winston =pgherveou
Expand Down
2 changes: 1 addition & 1 deletion lib/winston/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ exports.log = function (options) {
if (typeof options.prettyPrint === 'function') {
output += ' ' + options.prettyPrint(meta);
} else if (options.prettyPrint) {
output += ' ' + '\n' + util.inspect(meta, false, null, options.colorize);
output += ' ' + '\n' + util.inspect(meta, false, options.depth || null, options.colorize);
} else {
output += ' ' + exports.serialize(meta);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/winston/transports/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var Console = exports.Console = function (options) {
this.label = options.label || null;
this.logstash = options.logstash || false;
this.debugStdout = options.debugStdout || false;
this.depth = options.depth || null;

if (this.json) {
this.stringify = options.stringify || function (obj) {
Expand Down Expand Up @@ -74,7 +75,8 @@ Console.prototype.log = function (level, msg, meta, callback) {
prettyPrint: this.prettyPrint,
raw: this.raw,
label: this.label,
logstash: this.logstash
logstash: this.logstash,
depth: this.depth
});

if (level === 'error' || (level === 'debug' && !this.debugStdout) ) {
Expand Down
12 changes: 7 additions & 5 deletions lib/winston/transports/daily-rotate-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ var DailyRotateFile = exports.DailyRotateFile = function (options) {
this.prettyPrint = options.prettyPrint || false;
this.timestamp = options.timestamp != null ? options.timestamp : true;
this.datePattern = options.datePattern != null ? options.datePattern : '.yyyy-MM-dd';

this.depth = options.depth || null;

if (this.json) {
this.stringify = options.stringify;
}
Expand Down Expand Up @@ -156,7 +157,8 @@ DailyRotateFile.prototype.log = function (level, msg, meta, callback) {
prettyPrint: this.prettyPrint,
timestamp: this.timestamp,
label: this.label,
stringify: this.stringify
stringify: this.stringify,
depth: this.depth
}) + '\n';

this._size += output.length;
Expand Down Expand Up @@ -322,11 +324,11 @@ DailyRotateFile.prototype.stream = function (options) {
};

stream.destroy = common.tailFile(tail, function (err, line) {

if(err){
return stream.emit('error',err);
}

try {
stream.emit('data', line);
line = JSON.parse(line);
Expand All @@ -335,7 +337,7 @@ DailyRotateFile.prototype.stream = function (options) {
stream.emit('error', e);
}
});

if(stream.resume){
stream.resume();
}
Expand Down
4 changes: 3 additions & 1 deletion lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var File = exports.File = function (options) {
this.label = options.label || null;
this.timestamp = options.timestamp != null ? options.timestamp : true;
this.eol = options.eol || '\n';
this.depth = options.depth || null;

if (this.json) {
this.stringify = options.stringify;
Expand Down Expand Up @@ -131,7 +132,8 @@ File.prototype.log = function (level, msg, meta, callback) {
prettyPrint: this.prettyPrint,
timestamp: this.timestamp,
stringify: this.stringify,
label: this.label
label: this.label,
depth: this.depth
}) + this.eol;

this._size += output.length;
Expand Down
4 changes: 3 additions & 1 deletion lib/winston/transports/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var Memory = exports.Memory = function (options) {
this.prettyPrint = options.prettyPrint || false;
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;
this.label = options.label || null;
this.depth = options.depth || null;

if (this.json) {
this.stringify = options.stringify || function (obj) {
Expand Down Expand Up @@ -66,7 +67,8 @@ Memory.prototype.log = function (level, msg, meta, callback) {
timestamp: this.timestamp,
prettyPrint: this.prettyPrint,
raw: this.raw,
label: this.label
label: this.label,
depth: this.depth
});

if (level === 'error' || level === 'debug') {
Expand Down

0 comments on commit 0a848fa

Please sign in to comment.