UNPKG

pilsner

Version:

Crisp and effervescent logging for browser and server.

99 lines (89 loc) 2.96 kB
// Generated by CoffeeScript 1.10.0 var Sentry, getClient, winston, extend = 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; }, hasProp = {}.hasOwnProperty; 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(superClass) { extend(Sentry, superClass); 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.js.map