Python logging class in Docker: logs gone
<p>For several years now I've used Python's logging class in the same way:</p>

<pre><code>def get_module_logger(mod_name):
    """
    To use this, do logger = get_module_logger(__name__)
    """
    logger = logging.getLogger(mod_name)
    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)s [%(name)-12s] %(levelname)-8s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)
    return logger
</code></pre>

<p>Then in some module,</p>

<pre><code>logger = get_module_logger(__name__)
</code></pre>

<p>Now, I am running a Python app that uses this inside of a Docker container. I am running the container with <code>-d -i -t</code>. When I am inside the container after a <code>docker exec -it containername /bin/bash</code>, I can see the logs if I execute a command in my python script that produces logs. However, from outside, <code>docker logs containername</code> never shows anything. I have tried running my container with <code>PYTHONUNBUFFERED=0</code> per a few web posts and that did not help either. Tailing with <code>docker logs -f containername</code> never shows anything either. So all my logs, both stderr and stdout are empty. I have also tried <code>logging.StreamHandler(sys.stdout)</code> but to no avail. </p>

<p>What is wrong? Do I need to change something in the handler?</p>

<p>EDIT: my Dockerfile is very simple:</p>

<pre><code>FROM python:3.5.1
MAINTAINER tommy@...
ADD . /tmp

#need pip &gt; 8 to have internal pypi repo in requirements.txt
RUN pip install --upgrade pip 
#do the install
RUN pip install /tmp/py/

CMD myservice 
</code></pre>

<p>EDIT2:</p>

<pre><code>~ docker --version
Docker version 1.11.0, build 4dc5990
</code></pre>

<p>I was able to see the log outputs and was not able to reproduce your issue with your code.</p>

<p>I created a file called <code>tommy.py</code>:</p>

<pre><code>import logging

def get_module_logger(mod_name):
    """
    To use this, do logger = get_module_logger(__name__)
    """
    logger = logging.getLogger(mod_name)
    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)s [%(name)-12s] %(levelname)-8s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)
    return logger

if __name__ == "__main__":
    get_module_logger(__name__).info("HELLO WORLD!")
</code></pre>

<p>Ran the following:</p>

<pre><code>docker run -d -v /tmp/tommy.py:/opt/tommy.py python:3.5 python /opt/tommy.py
</code></pre>

<p>And saw this:</p>

<pre><code>$ docker logs -f sleepy_poincare 
2016-08-30 17:01:36,026 [__main__    ] INFO     HELLO WORLD!
</code></pre>

<p>Edit:<br>
Here's my Docker version:</p>

<pre><code>$ docker --version
Docker version 1.12.0, build 8eab29e
</code></pre>

python docker