ufoym / deepo

Setup and customize deep learning environment in seconds.
http://ufoym.com/deepo
MIT License
6.32k stars 750 forks source link

logging in python fails to write to STDOUT #130

Closed Genius1237 closed 4 years ago

Genius1237 commented 4 years ago

As of last week, using the logging library (with the default argument) to log statements in python would results in those statements appearing in STDOUT. As of today, this isn't happening, i.e all statements logged with logging are not appearing in STDOUT.

Has some change been made to images? I'm using pytorch-py36 btw.

Genius1237 commented 4 years ago

To add some info, previously using logging.info in a program would print the logged value to stdout, but it does not do so now.

ufoym commented 4 years ago

@Genius1237 Could you provide a minimal example for reproducing the problem?

Genius1237 commented 4 years ago

I seem to have narrowed down the issue. It has something to do with the pytorch installation in the docker image.

Running the following code-snippet shows the error. Run it with and without the line that does import torch. When the line is there, the message logged via logger.info does not appear on stdout.

import logging
import torch

logger = logging.getLogger(__name__)

def main():
    logging.basicConfig(format="%(asctime)s - %(levelname)s - %(name)s -   %(message)s",
                        datefmt="%m/%d/%Y %H:%M:%S",
                        level=logging.INFO)
    logger.info("info")
    logger.warn("warn")

if __name__ == "__main__":
    main()
ufoym commented 4 years ago

It is not due to PyTorch. See https://stackoverflow.com/questions/46989035/why-does-my-logging-not-work-in-python-3.

The following code works.

import logging
import torch
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info('ok')

To get your example to work, include logger.setLevel(logging.INFO) before logger.info().