2014-11-13 06:16:47 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
2014-10-17 02:21:06 +00:00
|
|
|
|
|
|
|
var bunyan = require('bunyan');
|
|
|
|
var paths = require('path');
|
2015-04-24 03:42:57 +00:00
|
|
|
var fs = require('fs');
|
2014-10-17 02:21:06 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init : function() {
|
2015-04-24 03:42:57 +00:00
|
|
|
var Config = require('./config.js').config;
|
2014-10-17 02:21:06 +00:00
|
|
|
//var ringBufferLimit = miscUtil.valueWithDefault(config.logRingBufferLimit, 100);
|
2015-04-24 03:42:57 +00:00
|
|
|
var logPath = Config.paths.logs;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create something a bit more friendly if the log directory cannot be used
|
|
|
|
//
|
|
|
|
// :TODO: this seems cheesy...
|
|
|
|
var logPathError;
|
|
|
|
try {
|
|
|
|
var pathStat = fs.statSync(logPath);
|
|
|
|
if(!pathStat.isDirectory()) {
|
|
|
|
logPathError = logPath + ' is not a directory!';
|
|
|
|
}
|
|
|
|
} catch(e) {
|
2015-04-24 22:54:25 +00:00
|
|
|
if('ENOENT' === e.code) {
|
|
|
|
logPathError = 'No such file or directory: ' + logPath;
|
|
|
|
} else {
|
|
|
|
logPathError = e.message;
|
|
|
|
}
|
2015-04-24 03:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(logPathError) {
|
|
|
|
console.error(logPathError);
|
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
2014-10-17 02:21:06 +00:00
|
|
|
var logFile = paths.join(logPath, 'enigma-bbs.log');
|
|
|
|
|
|
|
|
// :TODO: make this configurable --
|
|
|
|
// user should be able to configure rotations, levels to file vs ringBuffer,
|
|
|
|
// completely disable logging, etc.
|
|
|
|
|
|
|
|
this.log = bunyan.createLogger({
|
|
|
|
name : 'ENiGMA½ BBS',
|
|
|
|
streams : [
|
|
|
|
{
|
|
|
|
type : 'rotating-file',
|
|
|
|
path : logFile,
|
2015-07-21 04:56:48 +00:00
|
|
|
period : Config.logging.period || '1d',
|
2014-10-17 02:21:06 +00:00
|
|
|
count : 3,
|
2015-07-21 04:56:48 +00:00
|
|
|
level : Config.logging.level || 'debug',
|
2014-10-17 02:21:06 +00:00
|
|
|
}
|
|
|
|
/*,
|
|
|
|
{
|
|
|
|
type : 'raw',
|
|
|
|
stream : ringBuffer,
|
|
|
|
level : 'trace'
|
|
|
|
}*/
|
2016-07-16 19:05:32 +00:00
|
|
|
],
|
|
|
|
serializers: { err : bunyan.stdSerializers.err } // handle 'err' fields with stack/etc.
|
2014-10-17 02:21:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|