Skip to content

Commit

Permalink
Merge pull request #24 from ryanbreen/master
Browse files Browse the repository at this point in the history
Support arbitrary default meta values.
  • Loading branch information
jaakkos committed Aug 29, 2014
2 parents cd9eb6b + 5a86405 commit 75a9406
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/winston-logstash.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ var Logstash = exports.Logstash = function (options) {
this.ssl_cert = options.ssl_cert || '';
this.ca = options.ca || '';
this.ssl_passphrase = options.ssl_passphrase || '';
this.meta_defaults = options.meta || {};

// We want to avoid copy-by-reference for meta defaults, so make sure it's a flat object.
for (var property in this.meta_defaults) {
if (typeof this.meta_defaults[property] === 'object') {
delete this.meta_defaults[property];
}
}

this.label = options.label || this.node_name;

Expand Down Expand Up @@ -63,6 +71,10 @@ Logstash.prototype.log = function (level, msg, meta, callback) {
var self = this,
meta = winston.clone(meta || {}),
log_entry;

for (var property in this.meta_defaults) {
meta[property] = this.meta_defaults[property];
}

if (self.silent) {
return callback(null, true);
Expand Down

0 comments on commit 75a9406

Please sign in to comment.