Hi,
I'm writting a application using python standard logging system. I
encounter some problem with unicode message passed to logging library.
I found that unicode message will be messed up by logging handler.
piese of StreamHandler:
try:
self.stream.wri te(fs % msg)
except UnicodeError:
self.stream.wri te(fs % msg.encode("UTF-8"))
It just write the message to stream. If there is some unicode error,
it would rewrite msg with utf8 encoding.
I write some code to try:
import sys
print u'¤¤¤å¦r´ú¸Õ'
print sys.stdout.enco ding
sys.stdout.writ e(u'¤¤¤å')
result of that program:
¤¤¤å¦r´ú¸Õ
cp950
Traceback (most recent call last):
File "update_stockpr ice.py", line 92, in <module>
sys.stdout.writ e(u'ä¸*æ?')
UnicodeEncodeEr ror: 'ascii' codec can't encode characters in position
0-1: ordin
al not in range(128)
It show that....
1. print statement encode what it get with stream.encoding ?
2. stream.write don't do anything like encoding, just write it
(because it might be binary data?)
So the problem is : the StreamHandler of standard logging library use
stream.write to log message, if there is unicode error, unicode string
will be encode to utf8. This behavior mess my unicode up.
Here I modify the code of StreamHandler:
try:
print >self.stream, msg
#self.stream.wr ite(fs % msg)
except UnicodeError:
self.stream.wri te(fs % msg.encode("UTF-8"))
I replace stream.write with print statement, so that it will try to
use stream.encoding to encode msg. Now everything works fine.
My question is :
Could the behavior of StreamHandler be considered as a bug?
If it is, how to report this bug?
Is my solution correct?
Are there any side effect will caused by doing so?
If the code I write is fine, and solve that problem, how to report it
to Python's project?
I think this could be helpful for people who also encountered this
problem.
Thanks.
Victor Lin. 1 3411
On 13 Aug, 11:08, Victor Lin <Borns...@gmail .comwrote:
Hi,
I'm writting a application using python standardlogging system. I
encounter some problem with unicode message passed tologginglibrar y.
I found that unicode message will be messed up bylogginghandle r.
piese of StreamHandler:
try:
self.stream.wri te(fs % msg)
except UnicodeError:
self.stream.wri te(fs % msg.encode("UTF-8"))
It just write the message to stream. If there is some unicode error,
it would rewrite msg with utf8 encoding.
I write some code to try:
import sys
print u'¤¤¤å¦r´ú¸Õ'
print sys.stdout.enco ding
sys.stdout.writ e(u'¤¤¤å')
result of that program:
¤¤¤å¦r´ú¸Õ
cp950
Traceback (most recent call last):
File "update_stockpr ice.py", line 92, in <module>
sys.stdout.writ e(u'ä¸*æ?')
UnicodeEncodeEr ror: 'ascii' codec can't encode characters in position
0-1: ordin
al not in range(128)
It show that....
1. print statement encode what it get with stream.encoding ?
2. stream.write don't do anything like encoding, just write it
(because it might be binary data?)
So the problem is : the StreamHandler of standardlogging library use
stream.write to log message, if there is unicode error, unicode string
will be encode to utf8. This behavior mess my unicode up.
Here I modify the code of StreamHandler:
try:
print >self.stream, msg
#self.stream.wr ite(fs % msg)
except UnicodeError:
self.stream.wri te(fs % msg.encode("UTF-8"))
I replace stream.write with print statement, so that it will try to
use stream.encoding to encode msg. Now everything works fine.
My question is :
Could the behavior of StreamHandler be considered as a bug?
If it is, how to report this bug?
Is my solution correct?
Are there any side effect will caused by doing so?
If the code I write is fine, and solve that problem, how to report it
to Python's project?
I think this could be helpful for people who also encountered this
problem.
Thanks.
Victor Lin.
Hi Victor,
Can you try modifying your patch to use the following logic instead of
the print statement?
if hasattr(self.st ream, 'encoding'):
self.stream.wri te(fs % msg.encode(self .stream.encodin g))
else:
self.stream.wri te(fs % msg)
Does this work in your scenario?
Regards,
Vinay Sajip This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric DeWall |
last post by:
In trying to clean up the inevitable debug printing littered through some
code, I started reading up on the 'logging' module. Browsing groups
indicates that the design of the module is controversial but personally I'm
very happy to see such a full-featured logger as part of the standard
distribution. Here's my problem though (using 2.3.3) - I'm trying to write
some reusable classes that _optionally_ use the logging module. So a class...
|
by: Michael CATANZARITI |
last post by:
It's a flexible and highly configurable logging framework
Main features :
- Configurable logging destinations (appenders)
- Configurable logging format (layouts)
- Categorized logging statements through a hierarchy (loggers)
- Filtering filters (filters)
- Thread safe library
- UTF-16 Unicode support
* Appenders:
|
by: Thomas Heller |
last post by:
I'm about to add some logging calls to a library I have. How can I
prevent that the script that uses the library prints
'No handlers could be found for logger "comtypes.client"' when the
script runs?
I would like to setup the logging so that there is no logging when
nothing is configured, and no warning messages are printed.
Thomas
|
by: Ollie Riches |
last post by:
I am trying to use asynchronous logging using MSMQ and I have configured the
properties as defined in the help (see below) I don't understand where the
property 'MsmqPath' is in the app.config for MSMQDistrbutor.exe is it meant
to be an aplication settings or an enterprise library setting in the
app.config?
I have tried creating an application setting value for it but it still fails
to write to the logging destination?
Also is this...
|
by: Chumma Dede |
last post by:
Hi,
I need to code a DLL in .NET which logs the response times for our asp.net
multi-tier application. The problem is we need to log the timestamps at
multiple stages in a process lifecycle roundtrip without too much overhead.
We have two webservers which are load balanced and the back end tiers
include Biztalk and several remoting components all of which should ideally
use this same dll for logging timestamps in a central location in...
| |
by: robert |
last post by:
As more and more python packages are starting to use the bloomy
(Java-ish) 'logging' module in a mood of responsibility and as I am not
overly happy with the current "thickener" style of usage, I want to put
this comment and a alternative most simple default framework for
discussion.
Maybe there are more Python users which like to see that imported
(managed) logging issue more down-to-earth and flexible ? ...
Vinay Sajip wrote:
>...
|
by: Rasika WIJAYARATNE |
last post by:
Hi guys,
Please check this out:
http://rkwcoding.blogspot.com/2007/07/error-logging.html
|
by: Alexandru Mosoi |
last post by:
why doesn't logging throw any exception when it should? how do I
configure logging to throw exceptions?
.... logging.fatal('asdf %d', '123')
.... except:
.... print 'this line is never printed'
....
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 744, in emit
|
by: Thomas Heller |
last post by:
I'm using the logging module in my comtypes library to log
'interesting' things that happen. In other words, the idea
is if the user of the library is interested in the details that
happen in the package internally, he (she?) would configure
a logging level and handlers that write the log messages where it
is convenient.
This works great, with one exception:
If the script using the library does NOT configure logging, and somewhere the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |