lincoln
Version:
Presidential logging. Fancy loggers for winston.
105 lines (92 loc) • 2.71 kB
JavaScript
// Generated by CoffeeScript 1.6.3
var Logger, postmortem, utils, 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');
postmortem = require('postmortem');
utils = require('./utils');
Logger = (function(_super) {
__extends(Logger, _super);
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, v, _results;
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() {
var _this = this;
return process.on('uncaughtException', function(err) {
return _this.log('error', err, function() {
return process.exit(1);
});
});
};
return Logger;
})(winston.Logger);
module.exports = Logger;
/*
//@ sourceMappingURL=logger.map
*/