I can’t figure out how to log info-level messages to stdout, but everything else to stderr. I already read this http://docs.python.org/library/logging.html. Any suggestion?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The following script,
log1.py:when run, produces the following results.
As you’d expect, since on a terminal
sys.stdoutandsys.stderrare the same. Now, let’s redirect stdout to a file,tmp:So the INFO message has not been printed to the terminal – but the messages directed to
sys.stderrhave been printed. Let’s look at what’s intmp:So that approach appears to do what you want.