webapi-eca/js-coffee/new-logging.js
2014-02-18 09:48:18 +01:00

66 lines
1.6 KiB
JavaScript

// Generated by CoffeeScript 1.6.3
(function() {
var bunyan, exports, path,
_this = this;
path = require('path');
bunyan = require('bunyan');
/*
Module call
-----------
Calling the module as a function will act as a constructor and load the config file.
It is possible to hand an args object with the properties nolog (true if no outputs shall
be generated) and configPath for a custom configuration file path.
@param {Object} args
*/
exports = module.exports = function(args) {
var e, emptylog, opt;
emptylog = {
info: function() {},
warn: function() {},
error: function() {}
};
args = args != null ? args : {};
if (args.nolog) {
return emptylog;
} else {
try {
opt = {
name: "webapi-eca"
};
if (args['mode'] === 'development') {
opt.src = true;
}
if (args['file-path']) {
_this.logPath = path.resolve(__dirname, '..', 'logs', args['file-path']);
} else {
_this.logPath = path.resolve(__dirname, '..', 'logs', 'server.log');
}
opt.streams = [
{
level: args['io-level'],
stream: process.stdout
}, {
level: args['file-level'],
type: 'rotating-file',
path: _this.logPath,
period: '1d',
count: 3
}
];
return bunyan.createLogger(opt);
} catch (_error) {
e = _error;
console.error(e);
return emptylog;
}
}
};
}).call(this);