logging - merging multiple configuration files
<p>I am working on a project where we have a core application that loads multiple plugins.
Each plugin has its own configuration file, and the core application has one as well.</p>

<p>We are using the excellent logging module from python's standard library.
The logging module includes the ability to load the logging configuration from an .ini file.
However, if you load another configuration file, the other files are discarded and only the new configuration is used.</p>

<p>What I would like to do is to split my logging configuration into multiple files, so that the application can load its own configuration file and then load each plugin's merging their logging configuration into the main one.</p>

<p>Note: fileConfig has an option called disable_existing_loggers that can be set to False. However, this only keeps existing loggers alive, but it still clears the internal map of handlers (which means that a plugin's configuration cannot use a handler defined in the application's config file).</p>

<p>I could merge the files manually to produce my own config, but I'd rather avoid that.</p>

<p>Thanks.</p>

<hr>

<p>To make it clearer, I'd like to do something like this:</p>

<pre><code># application.ini
[loggers]
keys=root,app
[handlers]
keys=rootHandler,appHandler
[formatters]
keys=myformatter

[logger_root]
# stuff
[handler_rootHandler]
# stuff
[formatter_myformatter]
# stuff

...

# plugin.ini
[loggers]
keys=pluginLogger  # no root logger
[handlers]
keys=pluginHandler  # no root handler
# no formatters section

[logger_pluginLogger]
# stuff
formatter=myformatter # using the formatter from application.ini
</code></pre>

<p>I couldn't find a way to do what I wanted, so I ended up rolling a class to do it.</p>

<p>Here it is as a convenient <a href="https://gist.github.com/Ippo343/c2ab9d4ec03cc89b66211caf81b34545" rel="nofollow">github gist</a>.</p>

python python-2.7