473,396 Members | 2,030 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,396 software developers and data experts.

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.getLogger(appName)

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

log.fine = lambda msg, self=log, level=logging.FINE: self.log(level,
msg)
log.finer = lambda msg, self=log, level=logging.FINER: self.log(level,
msg)
log.finest = lambda msg, self=log, level=logging.FINEST:
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 1448
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.getLogger(appName)

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

log.fine = lambda msg, self=log, level=logging.FINE: self.log(level,
msg)
log.finer = lambda msg, self=log, level=logging.FINER: self.log(level,
msg)
log.finest = lambda msg, self=log, level=logging.FINEST:
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
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( )...
0
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' ...
6
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...
23
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...
6
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 ...
7
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...
1
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...
0
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...
16
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...
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: 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: 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
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
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,...
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.