Skip to content

Changing config on the fly

cihub edited this page Feb 3, 2012 · 15 revisions

The concept

Sealog was designed to be as stateless as possible: There is no initialization step, Sealog 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: sealog/test/stressconfig

How to change config on the fly

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. We are going to provide such config update checker as a helper utility later.

Clone this wiki locally