Skip to content

Commit

Permalink
add meta options to add custom fields to each log
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Binard committed Oct 6, 2015
1 parent 573c849 commit b72e00b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ 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.
* __meta:__ (Default **{}**) Custom fields to add to each log.

*Metadata:* Logged as JSON literal in Redis

Expand Down
6 changes: 4 additions & 2 deletions lib/winston-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var redis = require('redis'),
common = require('winston/lib/winston/common'),
util = require('util'),
Stream = require('stream').Stream,
async = require('async');
async = require('async'),
_ = require('lodash');

var Redis = exports.Redis = function (options) {
winston.Transport.call(this, options);
Expand All @@ -30,6 +31,7 @@ var Redis = exports.Redis = function (options) {
this.channel = options.pchannel || options.channel;
this.pattern = options.pattern || !!options.pchannel;
this.logstash = options.logstash === true;
this.metadata = options.meta || {};

if (options.auth) {
this.redis.auth(options.auth);
Expand Down Expand Up @@ -87,7 +89,7 @@ Redis.prototype.log = function (level, msg, meta, callback) {
var output = common.log({
level: level,
message: msg,
meta: meta,
meta: _.merge(meta, this.metadata),
json: this.json,
logstash: this.logstash,
colorize: this.colorize,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
],
"dependencies": {
"async": "^1.2.1",
"lodash": "3.10.x",
"redis": "0.12.x"
},
"devDependencies": {
Expand Down

0 comments on commit b72e00b

Please sign in to comment.