Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support winston 3 #47

Closed
wants to merge 20 commits into from
Closed
Changes from 8 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

44 lib/winston-loggly.js 100644 → 100755
@@ -6,10 +6,11 @@
*
*/

var events = require('events'),
var clone = require('clone'),
loggly = require('node-loggly-bulk'),
util = require('util'),
winston = require('winston'),
Transport = require('winston-transport'),
Stream = require('stream').Stream;

//
@@ -35,7 +36,7 @@ var Loggly = exports.Loggly = function (options) {
options.token = options.inputToken;
}

winston.Transport.call(this, options);
Transport.call(this, options);
if (!options.subdomain) {
throw new Error('Loggly Subdomain is required');
}
@@ -52,7 +53,7 @@ var Loggly = exports.Loggly = function (options) {
this.client = loggly.createClient({
subdomain: options.subdomain,
auth: options.auth || null,
json: options.json || false,
json: options.json || false, //TODO: should be false
proxy: options.proxy || null,
token: options.token,
tags: tags,
@@ -80,7 +81,7 @@ var flushLogsAndExit = exports.flushLogsAndExit = function () {
//
// Inherit from `winston.Transport`.
//
util.inherits(Loggly, winston.Transport);
util.inherits(Loggly, Transport);

//
// Define a getter so that `winston.transports.Loggly`
@@ -94,6 +95,16 @@ winston.transports.flushLogsAndExit = flushLogsAndExit;
//
Loggly.prototype.name = 'loggly';

const validateMetadata = (meta) => {
if (meta == null) {
return {};
} else if (typeof meta !== 'object') {
return { metadata: meta };
} else {
return clone(meta);
}
}

//
// ### function log (level, msg, [meta], callback)
// #### @level {string} Level at which to log the message.
@@ -103,21 +114,22 @@ Loggly.prototype.name = 'loggly';
// Core logging method exposed to Winston. Metadata is optional.
//
Loggly.prototype.log = function (level, msg, meta, callback) {

const message = validateMetadata(meta);

if (this.silent) {
return callback(null, true);
}

if (this.timestamp && (!meta || !meta.timestamp)) {
meta = meta || {};
meta.timestamp = (new Date()).toISOString();
if (this.timestamp && !message.timestamp) {
message.timestamp = (new Date()).toISOString();
}

if (this.stripColors) {
msg = ('' + msg).replace(code, '');
}

var message = Object.assign(meta || {}),
self = this;
const self = this;

message.level = level;
message.message = msg || message.message;
@@ -130,7 +142,7 @@ Loggly.prototype.log = function (level, msg, meta, callback) {
callback(err, true);
}

return meta && meta.tags
return (meta && meta.tags)
? this.client.log(message, meta.tags, logged)
: this.client.log(message, logged);
};
@@ -140,9 +152,9 @@ Loggly.prototype.log = function (level, msg, meta, callback) {
// #### @options {Object} Set stream options
// Returns a log stream.
//
Loggly.prototype.stream = function(options) {
Loggly.prototype.stream = function(maybeOptions) {
var self = this,
options = options || {},
options = maybeOptions || {},
stream = new Stream,
last,
start = options.start,
@@ -174,15 +186,15 @@ Loggly.prototype.stream = function(options) {
return setTimeout(check, 2000);
}

var result = res[res.length-1];
var result = results[results.length-1];
if (result && result.timestamp) {
if (last == null) {
last = result.timestamp;
return;
}
last = result.timestamp;
} else {
return func();
return;
}

results.forEach(function(log) {
@@ -235,10 +247,10 @@ Loggly.prototype.formatQuery = function (query) {
// ### function formatResults (results, options)
// #### @results {Object|Array} Results returned from `.query`.
// #### @options {Object} **Optional** Formatting options
// Formats the specified `results` with the given `options` accordinging
// Formats the specified `results` with the given `options` according
// to the implementation of this transport.
//
Loggly.prototype.formatResults = function (results, options) {
Loggly.prototype.formatResults = function (results, _options) {
return results;
};

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.