[Tutor] logging to cmd.exe
Peter Otten
__peter__ at web.de
Tue Sep 26 11:56:22 EDT 2017
Albert-Jan Roskam wrote:
[me]
> Or you follow the convention and log to stderr:
>
> $ python3 -c 'import sys; print("\udc85", file=sys.stderr)'
> \udc85
> $ $ python3 -c 'import logging; logging.basicConfig();
> logging.getLogger().warn("\udc85")' > to_prove_it_s_not_stdout
> WARNING:root:\udc85
[Albert-Jan]
> That's perhaps the best choice. But will messages with logging
> level warning and lower also be logged to stderr?
That are two distinct aspects. You may specify both what is logged and where
it is logged.
The easiest way to set up the filter is again basicConfig():
$ python3 -c 'from logging import *; basicConfig(); warn("important");
info("nice to know")'
WARNING:root:important
While the default level is WARNING you may specify something else:
$ python3 -c 'from logging import *; basicConfig(level=INFO);
warn("important"); info("nice to know")'
WARNING:root:important
INFO:root:nice to know
More information about the Tutor
mailing list