-
Notifications
You must be signed in to change notification settings - Fork 244
Changing config on the fly
Seelog was designed to be as stateless as possible: There is no initialization step, Seelog is immediately ready for logging right after importing its lib-path. If you want to refine your logger's configuration, you simply need to create a new xml config and call 'ReplaceLogger' func. The number of such reconfigurations is unlimited.
We have a test which demonstrates the logger switching in 1000 logging goroutines after each message.
It is located here: stresstest
Result of one of latest stress test runs:
~/.../github.com/cihub/seelog-examples/stresstest$ ./stresstest
Logger replaced 100001 times. Average replacement frequency: 4757.623047 times / second.
Output log is consistent: no log messages are missing or come in incorrect order.
PASS! Output is valid
The short answer is simple: call ReplaceLogger with a new logger at any moment of time. But the main thing here is to provide such functionality to your application users. For example, if you would like to change logging configuration of your server on-the-fly without restarting it, you need to create some kind of web-interface with a config text box and a 'submit' button that would consequently call 'log.LoggerFromBytes(...)' and 'log.ReplaceLogger'. If the LoggerFromBytes returned an error, like config syntax error, you should create a corresponding error web-page response.
Another option is to check whether the config file changed, and if so, create a config from new file bytes and call 'ReplaceLoger' if new config doesn't contain any errors.