lincoln
Version:
Presidential logging. Fancy loggers for winston.
101 lines (91 loc) • 2.98 kB
JavaScript
// Generated by CoffeeScript 1.6.3
var Sentry, getClient, winston,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
winston = require('winston');
getClient = (function() {
var Client;
Client = null;
return function() {
var prepareStackTrace;
if (Client != null) {
return Client;
}
prepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = null;
Client = require('raven').Client;
Error.prepareStackTrace = prepareStackTrace;
Client.prototype._process = Client.prototype.process;
Client.prototype._send = Client.prototype.send;
Client.prototype.send = function(kwargs) {};
Client.prototype.process = function(kwargs) {
var ret;
ret = this._process(kwargs);
if ((kwargs.module != null) && (kargs.method != null)) {
kwargs.culprit = "" + kwargs.module + "." + kwargs.method;
}
this._send(kwargs);
return ret;
};
return Client;
};
})();
Sentry = (function(_super) {
__extends(Sentry, _super);
function Sentry(options) {
var Client, _ref, _ref1;
this.name = 'sentry';
this.level = (_ref = options.level) != null ? _ref : 'info';
this._loggerName = (_ref1 = options.logger) != null ? _ref1 : 'root';
this._versionApp = options.appVersion;
this._versionNode = process.version;
this._versionOs = 'v' + require('os').release();
Client = getClient();
if (options.dsn == null) {
throw new Error('Sentry DSN must be declared');
}
this._client = new Client(options.dsn);
this._client.on('error', function(err) {
return console.error(err);
});
}
Sentry.prototype.log = function(level, message, metadata, callback) {
var kwargs, _ref;
if (typeof metadata === 'function') {
_ref = [metadata, {}], callback = _ref[0], metadata = _ref[1];
}
if (callback == null) {
callback = function() {};
}
if (metadata == null) {
metadata = {};
}
kwargs = {
extra: metadata,
level: level,
logger: this._loggerName,
tags: {
version_app: this._versionApp,
version_node: this._versionNode,
version_os: this._versionOs
}
};
if ((metadata.module != null) && (metadata.method != null)) {
kwargs.module = metadata.module;
kwargs.method = metadata.method;
}
if (level === 'error') {
this._client.captureError(message, kwargs);
} else {
this._client.captureMessage(message, kwargs);
}
return this._client.once('logged', function() {
return callback(null, true);
});
};
return Sentry;
})(winston.Transport);
module.exports = Sentry;
/*
//@ sourceMappingURL=sentry.map
*/