472,356 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,356 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 3298


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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.