Logging with hug and waitress
<p>I want to add logging to my Python <a href="http://www.hug.rest" rel="nofollow">hug</a> REST app. I couldn't find any wayto do it when serving the app through the <code>hug</code> command (via <code>hug -f app.py</code>), therefore I try to combine hug with <a href="https://github.com/Pylons/waitress/" rel="nofollow">waitress</a>.</p>

<p>My minimal app structure in the file <code>app.py</code> looks like:</p>

<pre><code>import logging
logger = logging.getLogger(__name__)
import hug
.
.
.
@hug.get()
def func(detail):
    logger.debug("debug func")
    .
    .
    .
</code></pre>

<p>And I serve this with a waitress script <code>run.py</code>:</p>

<pre><code>import logging
import waitress

import app

logger = logging.getLogger('waitress')
logger.setLevel(logging.DEBUG)
logger.debug("logger set to DEBUG")

waitress.serve(app.__hug_wsgi__)
</code></pre>

<p>When I execute  <code>python run.py</code> in a console, the app spins up nicely and the results of <code>func</code> are served back, however the debug messages from inside func ("debug func") <em>and</em> from <code>run.py</code> ("logger set to DEBUG") I cannot see in the console.</p>

<p>What is going wrong and how can I fix it? (I'm happy to use another (Windows-capable) WSGI server if that's easier.)</p>

<p>You have to configure logging for the <code>logging</code> module. Take a look at the <a href="https://docs.python.org/2/library/logging.config.html" rel="nofollow">documentation for <code>logging.config</code></a> (in particular <code>dictConfig</code> and <code>fileConfig</code>). As a start, to test whether it works, you can simply call</p>

<pre><code>logging.basicConfig()
</code></pre>

<p>in <code>app.py</code> before you do any logging. This will make the output of all channels go to <code>sys.stderr</code>.</p>

<p>Don't forget to do <code>logging.setLevel(logging.DEBUG)</code> in <code>app.py</code> too if you want the debug message there to be visible.</p>

python logging wsgi waitress hug