logging in python fails to write to STDOUT
Genius1237 opened this issue · 4 comments
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.
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.
@Genius1237 Could you provide a minimal example for reproducing the problem?
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()
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()
.