Skip to content

Commit f52ed9e

Browse files
committed
Fixed updating of config
1 parent 5eee698 commit f52ed9e

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

mods/config/index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ var read = require('./read')
55
var update = require('./update')
66
var notify = require('./notify')
77
var watch = require('./watch')
8-
9-
module.exports = {
8+
var config = module.exports = {
109
use: [
1110
require('../settings'),
1211
],
@@ -22,23 +21,26 @@ module.exports = {
2221
},
2322

2423
get: function(result, name) {
25-
var ulog = this
26-
if (!ulog.config) {
27-
ulog.config = {};
28-
var newCfg = read(ulog)
29-
var changed = update(ulog.config, newCfg)
30-
if (changed.length) notify(ulog, changed)
31-
watch(ulog)
24+
if (! this.config) {
25+
config.update(this)
3226
}
3327
if (!result) {
34-
var settings = grab(ulog, 'settings', {})
28+
var settings = grab(this, 'settings', {})
3529
name = settings[name] && settings[name].config || name
36-
result = ulog.config[name]
30+
result = this.config[name]
3731
}
3832
return result
3933
},
4034

35+
update: function(ulog) {
36+
ulog.config = ulog.config || {}
37+
var newCfg = read(ulog)
38+
var changed = update(ulog.config, newCfg)
39+
if (changed.length) notify(ulog, changed)
40+
watch(ulog)
41+
},
42+
4143
set: function(name) {
42-
if (name === 'log_config') this.config = read(this)
44+
if (name === 'log_config') config.update(this)
4345
}
4446
}

mods/config/watch.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ var notify = require('./notify')
77

88
module.exports = function(ulog) {
99
var filename = path.resolve(ulog.get('log_config') || 'log.config')
10+
console.info('watching ' + filename)
1011
try {
1112
fs.watch(filename, { persistent: false }, function() {
13+
console.info(filename + ' changed. reading it again')
1214
read(ulog, function(cfg){
1315
var changed = update(ulog.config, cfg)
1416
if (changed.length) notify(ulog, changed)

0 commit comments

Comments
 (0)