Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/winston-loggly.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ var events = require('events'),
winston = require('winston'),
Stream = require('stream').Stream;

//
// Remark: This should be at a higher level.
//
var code = /\u001b\[(\d+(;\d+)*)?m/g;

//
// ### function Loggly (options)
// #### @options {Object} Options for this instance.
Expand All @@ -37,18 +42,19 @@ var Loggly = exports.Loggly = function (options) {
}

this.name = 'loggly';
this.tags = options.tags || options.tag || options.id;
var tags = options.tags || options.tag || options.id;
if (tags && !Array.isArray(tags)) {
tags = [tags];
}

this.client = loggly.createClient({
subdomain: options.subdomain,
auth: options.auth || null,
json: options.json || false,
token: options.token
token: options.token,
tags: tags
});

if (this.tags && !Array.isArray(this.tags)) {
this.tags = [this.tags];
}

this.stripColors = options.stripColors || false;
};

Expand Down Expand Up @@ -82,12 +88,10 @@ Loggly.prototype.log = function (level, msg, meta, callback) {
}

if (this.stripColors) {
var code = /\u001b\[(\d+(;\d+)*)?m/g;
msg = ('' + msg).replace(code, '');
msg = ('' + msg).replace(code, '');
}

var message = winston.clone(meta || {}),
tags = meta.tags || this.tags,
self = this;

message.level = level;
Expand All @@ -101,7 +105,7 @@ Loggly.prototype.log = function (level, msg, meta, callback) {
callback(null, true);
}

return tags
return meta.tags
? this.client.log(message, tags, logged)
: this.client.log(message, logged);
};
Expand Down