473,569 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

logging magic

Hi everyone.

I've just been trying to add a bit more granularity to my logging code,
as the jump from INFO (level 20) to DEBUG (level 10) is a bit too big.
I was thinking of borrowing a few levels from java: fine (18), finer
(16) and finest(14).

This is what I've tried:

log = logging.getLogg er(appName)

logging.FINE = 18
logging.FINER = 16
logging.FINEST = 14

log.fine = lambda msg, self=log, level=logging.F INE: self.log(level,
msg)
log.finer = lambda msg, self=log, level=logging.F INER: self.log(level,
msg)
log.finest = lambda msg, self=log, level=logging.F INEST:
self.log(level, msg)

I could expand this to support kwargs, etc, but that's the least of my
problems.

The real issue is that by adding this extra method into the stack, the
logging module incorrectly reports the module name/line number. I
assume it's because logging.log(... ) accesses the stack to find out
where it was being invoked from.

Does anyone know I can add such methods to my log object and still have
it correctly report the context of the log message?

Thanks to all in advance.

Jun 12 '06 #1
1 1454
ni************* *@gmail.com wrote:
Hi everyone.

I've just been trying to add a bit more granularity to my logging code,
as the jump from INFO (level 20) to DEBUG (level 10) is a bit too big.
I was thinking of borrowing a few levels from java: fine (18), finer
(16) and finest(14).

This is what I've tried:

log = logging.getLogg er(appName)

logging.FINE = 18
logging.FINER = 16
logging.FINEST = 14

log.fine = lambda msg, self=log, level=logging.F INE: self.log(level,
msg)
log.finer = lambda msg, self=log, level=logging.F INER: self.log(level,
msg)
log.finest = lambda msg, self=log, level=logging.F INEST:
self.log(level, msg)

I could expand this to support kwargs, etc, but that's the least of my
problems.

The real issue is that by adding this extra method into the stack, the
logging module incorrectly reports the module name/line number. I
assume it's because logging.log(... ) accesses the stack to find out
where it was being invoked from.

Does anyone know I can add such methods to my log object and still have
it correctly report the context of the log message?

Thanks to all in advance.


Try using addLevelName (this will ensure that your level names are
correctly formatted in the log), and also try creating your own Logger
subclass which has the custom methods you want.

The logging system does walk up the stack, looking for a stack frame
whose corresponding source file is not the logging package itself. What
is the module name/file number which gets printed?

Regards,

Vinay Sajip

Jun 14 '06 #2

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

Similar topics

1
3658
by: jjesso | last post by:
I am trying to add a new logging level. logging.config.fileConfig("bengineLog.cfg") logging.CLIENT = logging.INFO + 1 logging.addLevelName( logging.CLIENT, 'CLIENT' ) logging.root.setLevel( ) logger = logging.getLogger(None) logging.Logger.client('test') I get error:
0
395
by: Karuppasamy | last post by:
H I am trying to use the Logging Module provided by Microsoft Application Blocks for .Net I installed everything as per the Instructions given in the 'Development Using the Logging Block' But when i am trying to run the sample, i am getting the following error in the Event Viwer Kindly help me on this
6
7310
by: pmatos | last post by:
Hi all, I am trying to create a simple but efficient C++ logging class. I know there are lots of them out there but I want something simple and efficient. The number one requirement is the possibility of shutting logging down at compile time and suffer no performance penalty whatsoever for getting logging on whenever I wish. Of course that...
23
2197
by: Rotem | last post by:
Hi, while working on something in my current project I have made several improvements to the logging package in Python, two of them are worth mentioning: 1. addition of a logging record field %(function)s, which results in the name of the entity which logged the record. My version even deduces the class name in the case which the logger...
6
10256
by: Burkhard Schultheis | last post by:
As I wrote last week, we have a problem with a DB2 V8 on Linux. Here is what is in db2diag.log during online backup: Starting a full database backup. 2004-04-01-02.33.54.760164 Instance:lzgneu Node:000 PID:1293(db2loggw (TELEMATX)) TID:1024 Appid:none data protection sqlpgwlp Probe:909 TailPage 0 does not match pagelsn...
7
2416
by: Jed Parsons | last post by:
Hi, I'm using the logging module for the first time. I'm using it from within Zope Extensions. My problem is that, for every event logged, the logger is producing multiple identical entries with the timestamp the same down to the millisecond. Is this something I'm doing wrong?
1
3526
by: fuzzylollipop | last post by:
I want a FileHandler to only log a single level say for example logging.INFO, and nothing else. do I need to create a custom Handler for this or is this doable with some magic that is not documeneted somewhere?
0
1843
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...
16
2582
by: per9000 | last post by:
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my previous python experiences: magic names (I felt almost as sad as when I discovered the strange pink worms that eat you in nethack, not to mention...
0
7703
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...
0
7619
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...
0
7930
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. ...
0
8138
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...
1
7681
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...
0
6290
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...
0
5228
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...
0
3662
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...
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.