[issue5170] logging to file + encoding

2009-04-22 Thread Vinay Sajip
Vinay Sajip added the comment: Fix checked into trunk and release26-maint. -- resolution: accepted -> fixed status: open -> closed ___ Python tracker ___

[issue5170] logging to file + encoding

2009-04-22 Thread Vinay Sajip
Vinay Sajip added the comment: > i think it's all about the difference betwin print(msg) and > sys.stdout.write('%s\n' % msg) Yes. Actually, it's about what streams will accept. For example, a stream opened with codecs.open(encoding='cp1251') will accept a Unicode string and encode it before ou

[issue5170] logging to file + encoding

2009-04-22 Thread shamilbi
shamilbi added the comment: > > Trunk and release26-maint were recently changed (r71657, r71658) to use > the following logic, which differs from the code snippet you posted. > >if (isinstance(msg, unicode) and >getattr(stream, 'encoding', None)): >

[issue5170] logging to file + encoding

2009-04-21 Thread Vinay Sajip
Vinay Sajip added the comment: Trunk and release26-maint were recently changed (r71657, r71658) to use the following logic, which differs from the code snippet you posted. if (isinstance(msg, unicode) and getattr(stream, 'encoding', None)):

[issue5170] logging to file + encoding

2009-04-21 Thread shamilbi
shamilbi added the comment: > > Can you retry with setting the "encoding" attribute of the file to > "cp1251"? That should work and that should be the appropriate method to > avoid the problem. > > test_logging.py in the Python distribution has a test which exercises > Unicode functionality usin

[issue5170] logging to file + encoding

2009-04-20 Thread Vinay Sajip
Vinay Sajip added the comment: Can you retry with setting the "encoding" attribute of the file to "cp1251"? That should work and that should be the appropriate method to avoid the problem. test_logging.py in the Python distribution has a test which exercises Unicode functionality using cp1251,

[issue5170] logging to file + encoding

2009-04-20 Thread shamilbi
shamilbi added the comment: (python 2.6.2, WinXP) logging to console stopped working. Here is a workaround: logging/__init__.py: class StreamHandler(Handler): ... def emit(self, record): ... if (isinstance(msg, unicode) or getattr(stream,

[issue5170] logging to file + encoding

2009-02-08 Thread Vinay Sajip
Vinay Sajip added the comment: Sorry, misread the original issue and tested with Python 2.5 rather than 2.6. This is a regression; fix and additional test case checked into trunk and release26-maint. -- resolution: works for me -> fixed status: pending -> closed ___

[issue5170] logging to file + encoding

2009-02-08 Thread shamilbi
shamilbi added the comment: test_log.py: --- #! -*- coding: windows-1251 -*- import logging logger = logging.getLogger('test_log') logger.addHandler(logging.FileHandler('test.log', encoding='cp1251')) logger.setLevel(logging.DEBUG) logger.debug(u'Привет')# russian Hello exception

[issue5170] logging to file + encoding

2009-02-06 Thread Vinay Sajip
Vinay Sajip added the comment: The attached test script and output file appear to show logging working correctly. The script writes a log message including the Cyrillic text доброе утро (Good morning) to a CP1251-encoded file, test.log. Opening this file in a Unicode-aware editor (I used BabelPa

[issue5170] logging to file + encoding

2009-02-06 Thread Benjamin Peterson
Changes by Benjamin Peterson : -- assignee: -> vsajip nosy: +vsajip ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue5170] logging to file + encoding

2009-02-06 Thread shamilbi
New submission from shamilbi : if i configure logging into a file with encoding = 'cp1251' and do logger.debug(u'...') then i get crash with UnicodeError i suggest reimplementing method FileHandler.emit(): ... if isinstance(msg, unicode): stream.write(f % msg)# it works! ... --