UNPKG

howsmydriving-twitter

Version:

Twitter abstraction for @HowsMyDrivingWA.

76 lines (74 loc) 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.log = exports.log4js_config_path = exports.__MODULE_VERSION__ = exports.__MODULE_NAME__ = void 0; var packpath = require("packpath"); var path = require("path"); var fs = require("fs"); var process_1 = require("./util/process"); 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; var temp_log4js_config_path = path.resolve(process_1.getAppRootPath() + '/dist/config/log4js.json'); if (!fs.existsSync(temp_log4js_config_path)) { throw new Error("Cannot find log4js.json: " + temp_log4js_config_path + "."); } exports.log4js_config_path = temp_log4js_config_path; var chokidar = require('chokidar'), log4js = require('log4js'); // 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'); temp_log.addContext('module', exports.__MODULE_NAME__); temp_log.info("howsmydriving-twitter: Adding log4js (" + exports.log4js_config_path + ") context: " + exports.__MODULE_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(log4js_config_path); log = log4js.getLogger('reason'); log.addContext('module', __MODULE_NAME__); }); }); */ } // 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); }); exports.log.info("Module " + exports.__MODULE_NAME__ + " version '" + exports.__MODULE_VERSION__ + "' loaded.");