From f52ed9e14b6101a4813e7348b1766a3d7cffb222 Mon Sep 17 00:00:00 2001 From: Stijn de Witt Date: Sat, 13 Feb 2021 18:08:26 +0100 Subject: [PATCH] Fixed updating of config --- mods/config/index.js | 26 ++++++++++++++------------ mods/config/watch.js | 2 ++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/mods/config/index.js b/mods/config/index.js index 1b30e89..9c8dc09 100644 --- a/mods/config/index.js +++ b/mods/config/index.js @@ -5,8 +5,7 @@ var read = require('./read') var update = require('./update') var notify = require('./notify') var watch = require('./watch') - -module.exports = { +var config = module.exports = { use: [ require('../settings'), ], @@ -22,23 +21,26 @@ module.exports = { }, get: function(result, name) { - var ulog = this - if (!ulog.config) { - ulog.config = {}; - var newCfg = read(ulog) - var changed = update(ulog.config, newCfg) - if (changed.length) notify(ulog, changed) - watch(ulog) + if (! this.config) { + config.update(this) } if (!result) { - var settings = grab(ulog, 'settings', {}) + var settings = grab(this, 'settings', {}) name = settings[name] && settings[name].config || name - result = ulog.config[name] + result = this.config[name] } return result }, + update: function(ulog) { + ulog.config = ulog.config || {} + var newCfg = read(ulog) + var changed = update(ulog.config, newCfg) + if (changed.length) notify(ulog, changed) + watch(ulog) + }, + set: function(name) { - if (name === 'log_config') this.config = read(this) + if (name === 'log_config') config.update(this) } } diff --git a/mods/config/watch.js b/mods/config/watch.js index acbd3e2..bf37c0f 100644 --- a/mods/config/watch.js +++ b/mods/config/watch.js @@ -7,8 +7,10 @@ var notify = require('./notify') module.exports = function(ulog) { var filename = path.resolve(ulog.get('log_config') || 'log.config') + console.info('watching ' + filename) try { fs.watch(filename, { persistent: false }, function() { + console.info(filename + ' changed. reading it again') read(ulog, function(cfg){ var changed = update(ulog.config, cfg) if (changed.length) notify(ulog, changed)