hmdwatest-seattle
Version:
Seattle region plug-in for @HowsMyDrivingWA.
47 lines (46 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Standard logging for HowsMyDriving modules.
*
* It is not required to use this. But if you do, your plugin module's
* logs will be integrated with the infrastructure logs and all the
* other plugin logs.
**/
var log4js = require('log4js'), chokidar = require('chokidar'), path = require('path');
// Load the config.
log4js.configure(path.resolve(__dirname + '/../../config/log4js.json'));
// Create default logger to log that our module was loaded and for
// config update changes.
exports.log = log4js.getLogger("result");
/**
* Monitor the log4js config file and reloading log instances if the file changes.
**/
var watcher = chokidar.watch(path.resolve(__dirname + '/../../config/log4js.json'), {
ignored: /(^|[\/\\])\../,
persistent: true,
awaitWriteFinish: true
});
/**
* Reload log4js (when config changes).
*
* Params:
* reason: Reason why logs are being reloaded. This is logged before
* reloading log4js.
*
* TODO: Test to make sure this works. Do existing loggers still work? Do
* they update to the new log level?
**/
function reloadlog(reason) {
exports.log.info("Reloading log config due to config file " + reason + ".");
log4js.shutdown(function () {
log4js.configure(__dirname + '/../../config/log4js.json');
exports.log = log4js.getLogger('reason');
});
}
// Handle the change/add events for the log4js config file.
watcher.on('add', function (path) {
reloadlog("add of " + path);
}).on('change', function (path) {
reloadlog("change of " + path);
});