Why get a new logger object in each new module?
<p>The python logging module has a common pattern (<a href="http://stackoverflow.com/a/15735146/52074">ex1</a>, <a href="https://docs.python.org/2/howto/logging.html#advanced-logging-tutorial" rel="nofollow">ex2</a>) where in each module you get a new logger object for each python module.</p>

<p>I'm not a fan of blindly following patterns and so I would like to understand a little bit more.</p>

<p><strong>Why get a new logger object in each new module?</strong></p>

<p>Why not have everyone just use the same root logger and configure the formatter with <code>%(module)s</code>?</p>

<p>Is there examples where this pattern is NECESSARY/NEEDED (i.e. because of some sort of performance reason[1])?</p>

<p>[1]
In a multi-threaded python program, is there some sort of hidden synchronization issues that is fixed by using multiple logging objects?</p>

<p>Each logger can be configured separately. Generally, a module logger is not configured <em>at all</em> in the module itself. You create a distinct logger and use it to log messages of varying levels of detail. Whoever <em>uses</em> the logger decides what level of messages to see, where to send those messages, and even how to display them. They may want everything (<code>DEBUG</code> and up) from one module logged to a file, while another module they may only care if a serious error occurs (in which case they want it e-mailed directly to them). If every module used the same (root) logger, you wouldn't have that kind of flexibility.</p>

python multithreading performance logging instrumentation