UNPKG

pilsner

Version:

Crisp and effervescent logging for browser and server.

104 lines (91 loc) 2.73 kB
// Generated by CoffeeScript 1.10.0 var Logger, postmortem, utils, 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'); postmortem = require('postmortem'); utils = require('./utils'); Logger = (function(superClass) { extend(Logger, superClass); function Logger(options) { var ref, ref1; if (options == null) { options = {}; } if (options.exitOnError == null) { options.exitOnError = false; } if (options.transports == null) { options.transports = []; } if (options.colors == null) { options.colors = { debug: 'blue', info: 'green', warn: 'yellow', error: 'red' }; } if (options.levels == null) { options.levels = { debug: 0, info: 1, warn: 2, error: 3 }; } this._nodeEnv = (ref = process.env.NODE_ENV) != null ? ref : 'development'; this._captureLocation = (ref1 = options.captureLocation) != null ? ref1 : true; postmortem.install(); Logger.__super__.constructor.call(this, options); } Logger.prototype.log = function(level, message, metadata, callback) { var ref; if (typeof metadata === 'function') { ref = [metadata, {}], callback = ref[0], metadata = ref[1]; } if (callback == null) { callback = function() {}; } if (metadata == null) { metadata = {}; } if (this._captureLocation) { utils.captureLocation(message, metadata); } if (metadata.error == null) { if (message instanceof Error) { metadata.error = message; message = message.toString(); } } return Logger.__super__.log.call(this, level, message, metadata, callback); }; Logger.prototype.configure = function(env, fn) { var k, results, v; if (typeof env === 'string') { if (env === this._nodeEnv) { return fn.call(this); } } else { results = []; for (k in env) { v = env[k]; results.push(this.configure(k, v)); } return results; } }; Logger.prototype.patchGlobal = function() { return process.on('uncaughtException', (function(_this) { return function(err) { return _this.log('error', err, function() { return process.exit(1); }); }; })(this)); }; return Logger; })(winston.Logger); module.exports = Logger; //# sourceMappingURL=logger.js.map