473,408 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

logging exceptions

why doesn't logging throw any exception when it should? how do I
configure logging to throw exceptions?
>>try:
.... 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
msg = self.format(record)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 630, in format
return fmt.format(record)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 418, in format
record.message = record.getMessage()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 288, in getMessage
msg = msg % self.args
TypeError: int argument required
Aug 26 '08 #1
4 3384


Alexandru Mosoi napisa³(a):
why doesn't logging throw any exception when it should? how do I
configure logging to throw exceptions?
>try:
... logging.fatal('asdf %d', '123')
... except:
... print 'this line is never printed'
...
[...]

You need to subclass your handler and redefine `handleError` method.
See: http://docs.python.org/lib/node409.html

HTH,
Rob
Aug 26 '08 #2
On Aug 26, 10:36 am, Alexandru Mosoi <brtz...@gmail.comwrote:
why doesn'tloggingthrow any exception when it should? how do I
configureloggingto throw exceptions?
>try:

... 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
msg = self.format(record)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 630, in format
return fmt.format(record)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 418, in format
record.message = record.getMessage()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 288, in getMessage
msg = msg % self.args
TypeError: int argument required
Was your traceback from the snippet you posted? If it was, then the
exception (a TypeError) *is* being raised from logging. So I don't
understand your question "why doesn't logging throw any exception when
it should?", because logging is raising an exception here.

To cause logging to *not* raise exceptions, set
logging.raiseExceptions to 0 (default is 1). The raiseExceptions
variable would normally be set to 0 in a production environment, where
you don't want logging-related exceptions to bring an application
down.

Regards,

Vinay Sajip
Aug 27 '08 #3


Vinay Sajip napisa³(a):
On Aug 26, 10:36 am, Alexandru Mosoi <brtz...@gmail.comwrote:
why doesn'tloggingthrow any exception when it should? how do I
configureloggingto throw exceptions?
>>try:
... 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
msg = self.format(record)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 630, in format
return fmt.format(record)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 418, in format
record.message = record.getMessage()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 288, in getMessage
msg = msg % self.args
TypeError: int argument required

Was your traceback from the snippet you posted? If it was, then the
exception (a TypeError) *is* being raised from logging. So I don't
understand your question "why doesn't logging throw any exception when
it should?", because logging is raising an exception here.
No, it isn't.
This traceback is *printed* in `Handler.handleError` method:

<code from logging>
__version__ = "0.5.0.2"

[...]

def handleError(self, record):
"""
Handle errors which occur during an emit() call.

This method should be called from handlers when an exception
is
encountered during an emit() call. If raiseExceptions is
false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors
in
the logging system, they are more interested in application
errors.
You could, however, replace this with a custom handler if you
wish.
The record which was being processed is passed in to this
method.
"""
if raiseExceptions:
ei = sys.exc_info()
traceback.print_exception(ei[0], ei[1], ei[2], None,
sys.stderr)
del ei

</code from logging>
>
To cause logging to *not* raise exceptions, set
logging.raiseExceptions to 0 (default is 1). The raiseExceptions
variable would normally be set to 0 in a production environment, where
you don't want logging-related exceptions to bring an application
down.
Well, I think that it will not help. The exception will be printed
not raised. The only solution is to redefine `handleError` method
or maybe I've missed something?

Br,
Rob
Aug 27 '08 #4
On Aug 27, 10:30 am, Rob Wolfe <r...@smsnet.plwrote:
Vinay Sajip napisa³(a):
On Aug 26, 10:36 am, Alexandru Mosoi <brtz...@gmail.comwrote:
why doesn'tloggingthrow any exception when it should? how do I
configureloggingto throw exceptions?
>try:
... 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
msg = self.format(record)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 630, in format
return fmt.format(record)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 418, in format
record.message = record.getMessage()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 288, in getMessage
msg = msg % self.args
TypeError: int argument required
Was your traceback from the snippet you posted? If it was, then the
exception (a TypeError) *is* being raised fromlogging. So I don't
understand your question "why doesn'tloggingthrow any exception when
it should?", becauseloggingis raising an exception here.

No, it isn't.
This traceback is *printed* in `Handler.handleError` method:
You're right - silly me. I wasn't paying attention :-(
variable would normally be set to 0 in a production environment, where
you don't wantlogging-related exceptions to bring an application
down.

Well, I think that it will not help. The exception will be printed
not raised. The only solution is to redefine `handleError` method
or maybe I've missed something?

No, you're right. To do custom handling of exceptions, handleError
needs to be overridden.

Regards,

Vinay
Aug 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeremy Fincher | last post by:
I've just converted my application to use the logging module for its logging needs (it's quite excellent, actually :)). One thing I still have to resolve, though: in many places in my application,...
0
by: Ayende Rahien | last post by:
I'm more than a little bit confused regarding logging & exception handling. To start with, I want to use a single point in my applications for logging and possibly for exception handling. My...
6
by: Kevin Jackson | last post by:
Let's say we log exceptions to the windows application event log using the Exception Management Application Block. Is there a pattern that can be used so the exception is logged only once and not...
16
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some...
4
by: Julia | last post by:
Hi, So my server is complete,I have all the code and libraries which I need but now I want to add exception management and logging capabilities I would like you to suggest a good book about...
17
by: Cramer | last post by:
I plan to implement an exception logging feature in an ASP.NET Web application that writes encountered exceptions to disk. The exception data will be stored as XML. I am planning on having each...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.