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

example of logging w/ user-defined keywords?

Several things that I've read lead me to think this is possible, but I
can't figure out how to do it. I have some information (a "job
number") that I would like logged on every log message, just like the
time or the severity.

I saw some mail threads that suggested that there was an easy way to do
this, but I havent' found any examples. Is there a simple way to do
this, or do I need to write my own logger subclass?

Apr 12 '06 #1
2 941
Chris Curvey wrote:
Several things that I've read lead me to think this is possible, but I
can't figure out how to do it. I have some information (a "job
number") that I would like logged on every log message, just like the
time or the severity.

I saw some mail threads that suggested that there was an easy way to do
this, but I havent' found any examples. Is there a simple way to do
this, or do I need to write my own logger subclass?


class MyClass:
def __init__(self, name, job):
self.logger = logging.getLogger(name)
self.job = job
def log(self, msg):
self.logger.debug('#%d: %s' % (self.job, msg)
Then just call self.log('foo') whenever you want to log something.

If this isn't sufficient please describe what requirements you have that
it doesn't meet. (Subclassing Logger is certainly a simple way to do it
though... in that case you would just pass the job number to the
subclass when you construct it and it could do something like that above.

-Peter

Apr 12 '06 #2
Chris Curvey wrote:
Several things that I've read lead me to think this is possible, but I
can't figure out how to do it. I have some information (a "job
number") that I would like logged on every log message, just like the
time or the severity.

I saw some mail threads that suggested that there was an easy way to do
this, but I havent' found any examples. Is there a simple way to do
this, or do I need to write my own logger subclass?


The latest version in Subversion has an 'extra' keyword argument which
allows almost arbitrary items to be added to a LogRecord. See the
"in-development" docs at

http://docs.python.org/dev/lib/node365.html

and search for "extra".

Best regards,

Vinay Sajip

Apr 13 '06 #3

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

Similar topics

5
by: j vickroy | last post by:
Hello, I'm trying to understand the behavior of the Python 2.3 logging module (MS Windows 2k) with regard to RotatingFileHandler. The following script illustrates a puzzling problem. What is...
6
by: Ville Vainio | last post by:
Just posting this for the sake of google: Like everyone else, I figured it's time to start using the 'logging' module. I typically want to dump "info" level (and up) log information to...
1
by: Gram | last post by:
Hello, Can anoyone help me with the following: I have a application online using ASP in which users log in and log out. However, a lot of users simply close the window, bypassing my log-out...
3
by: Chris Smith | last post by:
Hola, pythonisas: The documentation for the logging module is good, but a bit obscure. In particular, there seems to be a lot of action at a distance. The fact that getLogger() can actually be a...
2
by: philip.mckee | last post by:
Hi Looking for some very general advice. I have a classic asp content management application which I am porting to ASP.NET. The database is SQL server, and it is hoped that we can leverage this...
3
by: nicholas.petrella | last post by:
I am currently trying to use the python logging system as a core enterprise level logging solution for our development and production environments. The rotating file handler seems to be what I...
2
by: ZHENG Zhong | last post by:
Hi, I implemented a small logging library with the API like this: logger& log = log_manager::instance().get_logger("my_logger"); log.stream(DEBUG) << "this is a debug message" << std::endl;...
3
by: Lowell Alleman | last post by:
Here is the situation: I wrote my own log handler class (derived from logging.Handler) and I want to be able to use it from a logging config file, that is, a config file loaded with the...
6
by: Larry Bates | last post by:
Every time I look at the logging module (up until now) I've given up and continue to use my home-grown logger that I've been using for years. I'm not giving up this time ;-) I find that I...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.