473,388 Members | 1,330 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,388 software developers and data experts.

Controlling exception handling of logging module

sj
Suppose the following are part of a long file and executed:

logging.basicConfig(stream = sys.stderr, level=logging.INFO)
logging.info("%d %d", 1, 2, 3) # buggy

Python prints the traceback of the error as follows:

Traceback (most recent call last):
File ".../local/lib/python2.4/logging/__init__.py", line 706, in emit
msg = self.format(record)
File ".../local/lib/python2.4/logging/__init__.py", line 592, in
format
return fmt.format(record)
File ".../local/lib/python2.4/logging/__init__.py", line 382, in
format
record.message = record.getMessage()
File ".../local/lib/python2.4/logging/__init__.py", line 253, in
getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting

It tells why error occurred, but the traceback is not helpful to locate
where it occurred. I believe that's because the logging module caught
and ate up the exception. I understand that this is a sensible setting
as logging shouldn't harm the main program, but in the debugging phase,
I really want this exception to propagate up so that I can easily
locate from my code. Is there any way to control this behavior so the
error is not handled by the logging module itself?

Oct 19 '05 #1
3 1832
make the second statement 'logging.info("%d %d", 1, 2)' or
'logging.info("%d %d %d", 1, 2, 3)', and all works. for every argument
you want to log you need one format specifier

Oct 19 '05 #2
sj
Thanks, but my point wasn't fixing the bug. I'd like the logging
module to raise an exception on this occasion (rather than print and
consume the error) so that I can find the bug easily. If those two
lines were part of 10,000-line code, I'd have to check all logging
statements one-by-one.

Oct 19 '05 #3

sj wrote:
Thanks, but my point wasn't fixing the bug. I'd like the logging
module to raise an exception on this occasion (rather than print and
consume the error) so that I can find the bug easily. If those two
lines were part of 10,000-line code, I'd have to check all logging
statements one-by-one.


You'll need to subclass your handler and redefine handleError(), which
is called when an exception is raised during a handler's emit()
operation. See

http://www.red-dove.com/logging/publ...ml#handleError

Oct 19 '05 #4

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

Similar topics

2
by: Edward C. Jones | last post by:
Is there a better way to write the following? -------- import sys, traceback class LocalError(StandardError): pass _first = True
1
by: Abelardo Vacca | last post by:
Hello, I am currently in the process of switching our application to a N-Tier model with .NET. One of the aspects we want ot get right from the start not to worry about it after is the...
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...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
4
by: sm | last post by:
Hi, I have a couple of questions with regards to handling errors and exceptions. 1. If I use On Error goto Errhandler ... Errhandler:
8
by: kbperry | last post by:
In Python, When using the default except (like following) try: some code that might blow up except: print "some error message"
1
by: Jarsinio | last post by:
I have some doubts about how managed exception in a VB.net aplication. In my aplicattion I have 3 clases: One clase is the UI ( Windows Forms). This class call a second clase who perform an...
3
by: Robert Rawlins | last post by:
Hi Mk, Yeah it's got me a little bemused to be honest, I've tried playing around with configuration options this morning and not been able to achieve anything that works properly. I'll keep...
0
by: srizzler | last post by:
Hi All: I am trying to implement Exception Handling using Enterprise Library 3.1's Exception Handling Application Block as well as Logging Blocks. I have a windows application developed in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
jinu1996
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...
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...

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.