473,785 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Controlling exception handling of logging module

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

logging.basicCo nfig(stream = sys.stderr, level=logging.I NFO)
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(rec ord)
File ".../local/lib/python2.4/logging/__init__.py", line 592, in
format
return fmt.format(reco rd)
File ".../local/lib/python2.4/logging/__init__.py", line 382, in
format
record.message = record.getMessa ge()
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 1845
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
1601
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
1855
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 Exception management. I have read two MSDN documents that appear to be in contradiction, and I would like to know if someone can explain to me which of the two is the
6
9969
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 everytime up through the call chain? Is there anything a caller can key off of to check to see if it should also log the exception?
44
4229
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 user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
4
1847
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
1464
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
1458
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 action ( for example add a item in the database). The last class is the one who conect to the DB ( ms access) How I should manage an exception ? * What I must do when an exception occurs when the class number 3 wants to make a DB coneection an...
3
2042
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 testing though and as soon as I have a root cause to the problem I'll be sure to let the list know.
0
2195
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 VB.Net (Visual Studio 2005) which have three tiers: User Interface Business Logic Data Layer
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9485
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,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
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 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...
1
10098
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,...
0
9958
tracyyun
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...
0
8986
agi2029
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...
0
6743
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();...
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.