Opened 6 years ago

Closed 6 years ago

#3368 defect closed duplicate (duplicate)

twisted.python.log can't encode unicode correctly

Reported by: victorlin Owned by:
Priority: low Milestone:
Component: core Keywords: logging
Cc: Branch:
Author: Launchpad Bug:

Description

I encounter a problem. Once I send unicode message to log.msg or stdout (replaced by a proxy class), I got a UnicodeEncodeError: 'ascii' error. I try to use the patch in ticket #1990, but it does not work. There is no problem to display unicode in console of pydev (a python plug of eclipse), but it throw unicode encode exception in cmd of windows. I think the problem is that it should encode the unicode with 'cp950' on my computer's console environment, but it try to encode everything to 'ascii'. Could you fix this problem? My program Can't work around because this encoding problem. Thanks.

# this is the code to show the problem
# I have no idea does this problem occur in ascii environment
# But it occurs on my computer : Traditional Chinese Windows's cmd

from twisted.python import log

import sys
log.startLogging(sys.stdout)

from twisted.python.logfile import DailyLogFile
log.startLogging(DailyLogFile('log', '.'))

print u'中文'
log.msg(u'中文')

Change History (3)

comment:1 Changed 6 years ago by itamar

  • Keywords logging added; log unicode encoding problem removed
  • Priority changed from normal to low

Why not write your own logging wrapper around Twisted's?

from twisted.python import log
import sys

def mylogmsg(s):
    log.msg(s.encode(sys.getdefaultencoding()))

comment:2 Changed 6 years ago by exarkun

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #1990 and #989.

comment:3 Changed 3 years ago by <automation>

  • Owner glyph deleted
Note: See TracTickets for help on using tickets.