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>