Skip to content

Commit

Permalink
Allow using logstash option with the File transport
Browse files Browse the repository at this point in the history
  • Loading branch information
gmajoulet authored and indexzero committed Oct 6, 2014
1 parent b806389 commit d5ebcb3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ There are two different ways to use winston: directly via the default logger, or
* [Transports](https://github.com/flatiron/winston/blob/master/docs/transports.md)
* [Profiling](#profiling)
* [Streaming Logs](#streaming-logs)
* [Querying Logs](#querying-logs)
* [Querying Logs](#querying-logs)
* [Exceptions](#exceptions)
* [Handling Uncaught Exceptions with winston](#handling-uncaught-exceptions-with-winston)
* [To Exit or Not to Exit](#to-exit-or-not-to-exit)
Expand Down Expand Up @@ -126,7 +126,7 @@ In addition to logging messages and metadata, winston also has a simple profilin
All profile messages are set to the 'info' by default and both message and metadata are optional There are no plans in the Roadmap to make this configurable, but I'm open to suggestions / issues.

### String interpolation
The `log` method provides the same string interpolation methods like [`util.format`][10].
The `log` method provides the same string interpolation methods like [`util.format`][10].

This allows for the following log messages.
``` js
Expand Down Expand Up @@ -184,7 +184,7 @@ Specifically: `File`, `Couchdb`, `Redis`, `Loggly`, `Nssocket`, and `Http`.
if (err) {
throw err;
}

console.log(results);
});
```
Expand Down Expand Up @@ -327,7 +327,7 @@ You may also dynamically change the log level of a transport:
new (winston.transports.Console)({ level: 'warn' }),
new (winston.transports.File)({ filename: 'somefile.log', level: 'error' })
]
});
});
logger.debug("Will not be logged in either transport!");
logger.transports.console.level = 'debug';
logger.transports.file.level = 'verbose';
Expand Down Expand Up @@ -625,7 +625,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).
* __logstash:__ If true, messages will be logged using the logstash JSON format.
* __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 +637,7 @@ The File transport should really be the 'Stream' transport since it will accept

The Loggly transport is based on [Nodejitsu's][3] [node-loggly][6] implementation of the [Loggly][7] API. If you haven't heard of Loggly before, you should probably read their [value proposition][8]. The Loggly transport takes the following options. Either 'inputToken' or 'inputName' is required:

* __level:__ Level of messages that this transport should log.
* __level:__ Level of messages that this transport should log.
* __subdomain:__ The subdomain of your Loggly account. *[required]*
* __auth__: The authentication information for your Loggly account. *[required with inputName]*
* __inputName:__ The name of the input this instance should log to.
Expand All @@ -662,7 +662,7 @@ In addition to the options accepted by the [riak-js][3] [client][4], the Riak tr
``` js
// Use a single bucket for all your logs
var singleBucketTransport = new (Riak)({ bucket: 'some-logs-go-here' });

// Generate a dynamic bucket based on the date and level
var dynamicBucketTransport = new (Riak)({
bucket: function (level, msg, meta, now) {
Expand Down Expand Up @@ -723,7 +723,7 @@ The Mail transport uses [emailjs](https://github.com/eleith/emailjs) behind the
* __password__ Password for server auth
* __ssl:__ Use SSL (boolean or object { key, ca, cert })
* __tls:__ Boolean (if true, use starttls)
* __level:__ Level of messages that this transport should log.
* __level:__ Level of messages that this transport should log.
* __silent:__ Boolean flag indicating whether to suppress output.

*Metadata:* Stringified as JSON in email.
Expand Down Expand Up @@ -870,7 +870,7 @@ Adding a custom transport (say for one of the datastore on the Roadmap) is actua
```

## Run Tests
All of the winston tests are written in [vows][9], and designed to be run with npm.
All of the winston tests are written in [vows][9], and designed to be run with npm.

``` bash
$ npm test
Expand Down
2 changes: 1 addition & 1 deletion lib/winston/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ exports.log = function (options) {
//
// json mode is intended for pretty printing multi-line json to the terminal
//
if (options.json) {
if (options.json || true === options.logstash) {
if (typeof meta !== 'object' && meta != null) {
meta = { meta: meta };
}
Expand Down
2 changes: 2 additions & 0 deletions lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var File = exports.File = function (options) {
}

this.json = options.json !== false;
this.logstash = options.logstash || false;
this.colorize = options.colorize || false;
this.maxsize = options.maxsize || null;
this.maxFiles = options.maxFiles || null;
Expand Down Expand Up @@ -123,6 +124,7 @@ File.prototype.log = function (level, msg, meta, callback) {
message: msg,
meta: meta,
json: this.json,
logstash: this.logstash,
colorize: this.colorize,
prettyPrint: this.prettyPrint,
timestamp: this.timestamp,
Expand Down

0 comments on commit d5ebcb3

Please sign in to comment.