Message262762
Many examples in the internet only show the usage of the filename parameter of basicConfig() and almost no one shows how to use the stream. That's why I wanted to use the filename parameter. But now I tested other options and they work for me. My case may be very specific as I need to log words in very different languages including not only those having the Latin script but also cyrillic - Russian, Greek etc.
Regarding the codecs module and open() - yes, I made a mistake. There is no need for that in Python3.
About sys.stdout. I understand the redirection in the following way (also shown in the Dive Into Python book):
normal_stdout = sys.stdout
sys.stdout = open(mylogfile, 'w', encoding='utf-8')
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
After that, all the STDOUT goes to mylogfile. In order to send the output to the terminal window again, sys.stdout must be set back to normal:
sys.stdout = normal_stdout |
|
Date |
User |
Action |
Args |
2016-04-01 19:47:31 | janis.slapins | set | recipients:
+ janis.slapins, vinay.sajip |
2016-04-01 19:47:31 | janis.slapins | set | messageid: <1459540051.67.0.836733968292.issue26606@psf.upfronthosting.co.za> |
2016-04-01 19:47:31 | janis.slapins | link | issue26606 messages |
2016-04-01 19:47:31 | janis.slapins | create | |
|