[issue26606] logging.baseConfig is missing the encoding parameter
Jānis Šlapiņš added the comment: > that's why I'm choosing not to increase the complexity of my code I disagree about the classification of my proposal. This is not about increasing the complexity (changing algorithms, adding a new functionality and so on). It is just about getting the most out of the code with a minimum effort. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26606> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26606] logging.baseConfig is missing the encoding parameter
Jānis Šlapiņš added the comment: 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 -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26606> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26606] logging.baseConfig is missing the encoding parameter
Jānis Šlapiņš added the comment: Yes, it also works. But then you have also to remember to restore sys.stdout to the initial state at the end. In addition, for non-English languages it would be more appropriate to use codecs.open() instead of just open() in this case. The complexity of the code grows and increases a danger of "more code, more bugs". Why to use a "detour" and try always to remember that a part of a module is not useful for you due to particual drawbacks if it is possible to implement a small addition in it that does not break anything? -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26606> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26606] logging.baseConfig is missing the encoding parameter
Jānis Šlapiņš added the comment: Using the stream or other options requires much more coding (for example, an additional redirection of sys.stdout to a file) instead of just one line with the basicConfig. In the meanwhile, I tried to use logging.FileHandler instead where I could specify the encoding in parameters and it works as I wanted when used the basicConfig method. Anyway, it would be nice to have the encoding parameter among the basicConfig parameters when logging to files. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26606> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26606] logging.baseConfig is missing the encoding parameter
New submission from Jānis Šlapiņš: Hi! Log files are only saved using the system default encoding. On Windows, this means that the current ANSI code page is used. This may lead to a disaster (exceptions may be thrown due to unmappable characters) if you want to log particular text strings in a foreign language, e.g. those read from a source file in the UTF-8 or UTF-16 encoding, and such strings contain characters not available in your ANSI code page. I guess this issue does not affect Linux or Mac OSX as they already use the UTF-8 encoding for their system locales. Actually, the logging module already has the built-in functionality for setting a particular encoding for output files. However, it was not added as a parameter of the baseConfig function (in __init__.py). I added a patch file with suggested amendments. I already tested writing logs with those changes applied and files are now saved in the specified encoding which differs from the Windows current ANSI page. For example: logging.basicConfig(filename=log_path, filemode='w', encoding='utf-8', format='%(message)s', level=logging.INFO) -- components: Library (Lib) files: __init__.py.patch keywords: patch messages: 262150 nosy: janis.slapins priority: normal severity: normal status: open title: logging.baseConfig is missing the encoding parameter type: enhancement versions: Python 3.5 Added file: http://bugs.python.org/file42238/__init__.py.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26606> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com