howsmydriving-nyc
Version:
NYC region plug-in for @HowsMyDrivingWA.
75 lines (74 loc) • 2.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var packpath = require("packpath");
var path = require("path");
var fs = require("fs");
var process_1 = require("./util/process");
exports.__REGION_NAME__ = 'New York City';
var packpath_parent = packpath.parent() ? packpath.parent() : packpath.self();
var packpath_self = packpath.self();
var package_json_path = path.resolve(__dirname + '/../package.json');
if (!fs.existsSync(package_json_path)) {
package_json_path = path.resolve(__dirname + '/../../package.json');
if (!fs.existsSync(package_json_path)) {
throw new Error("Cannot find package.json: " + __dirname + ".");
}
}
var pjson = require(package_json_path);
// Put this at very top so other modules can import it without taking
// dependencies on something else in the module being instantiated.
exports.__MODULE_NAME__ = pjson.name;
exports.__MODULE_VERSION__ = pjson.version;
exports.log4js_config_path = path.resolve(process_1.getAppRootPath() + '/dist/config/log4js.json');
/**
* 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');
// Load the config.
log4js.configure(exports.log4js_config_path);
// Create default logger to log that our module was loaded and for
// config update changes.
var temp_log = log4js.getLogger('result', exports.__REGION_NAME__ + ": ");
temp_log.addContext('module', exports.__REGION_NAME__);
exports.log = temp_log;
/**
* Monitor the log4js config file and reloading log instances if the file changes.
**/
var watcher = chokidar.watch(exports.log4js_config_path, {
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) {
/*
log.info(`Reloading log config due to config file ${reason}.`);
log4js.shutdown(() => {
sleep(10000).then(() => {
log4js.configure(config_path);
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);
});