473,387 Members | 1,578 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.

Re: Extending Logger

Yes but in the other hand :http://docs.python.org/library/loggi...logger-objects
"Note that Loggers are never instantiated directly, but always through
the module-level function logging.getLogger(name)."
That is part of the power of the logging module. If you ask for a
logger of the same name in two different place you will get the same
object. That way you don't have to pass the logger instances around,
and it always has the same properties (same handlers attached, same
level, etc.). If you want to add functionality you getLoggerClass,
inherit from that, then setLoggerClass, and use the regular logging
facilities to instantiate them.

The only limitation here is that you can't change the constructor.
Well, it isn't useful to change the constructor. You can add a method
that does the same thing.

I can't help but feel that if you have a problem with this, you simply
aren't using the Logging module the way it was meant to be used.

Matt
Nov 7 '08 #1
1 2832
On Nov 7, 8:23*pm, Matimus <mccre...@gmail.comwrote:
Yes but in the other hand :http://docs.python.org/library/loggi...logger-objects
"Note that Loggers are never instantiated directly, but always through
the module-level function logging.getLogger(name)."

That is part of the power of the logging module. If you ask for a
logger of the same name in two different place you will get the same
object. That way you don't have to pass the logger instances around,
and it always has the same properties (same handlers attached, same
level, etc.). If you want to add functionality you getLoggerClass,
inherit from that, then setLoggerClass, and use the regular logging
facilities to instantiate them.

The only limitation here is that you can't change the constructor.
Well, it isn't useful to change the constructor. You can add a method
that does the same thing.

I can't help but feel that if you have a problem with this, you simply
aren't using the Logging module the way it was meant to be used.

Matt
Thanks for your answers.
Well, I just wanted to point out that there's maybe a little problem
in the design of Logger since we don't have to know what's the Logger
constructor, except when inheriting from it (for instance, the
documentation doesn't give the parameters of Logger.__init__()). So, i
thought Logger wasn't really made to be inherited.

Also, i dislike the fact that loggers are global, and that we have to
use setLoggerClass before any call to getLogger : we can't be sure
that no logger have been created before. These kind of issues are well
known in C programs, when some global stuff need to be initiated, we
don't know how it's done and when, so the clean way is usually to have
an object created/destroyed manually and passed in parameters of
functions needing it.
Yes i know it's more convinient to get rid of passing the object
through all the code and for most people it's an interesting feature,
but to me it could have been better if using a global system was not
mandatory.

So now, i feel shared between the following possibilities :
1) Using a global logger, setting the class in the beginning of my
program (this may not be easy), using getLogger in the different parts
of my application
2) Using a global logger, not subclassing Logger, stay with the
standard methods and deal with the Handlers/Formatters to customize
some of what i want to do. After all, i only wanted to add convenience
methods to log errors of specific type.
3) Making a class that handles internally a global logger (whose name
is not to be known by the class user) and only create methods that i
need.
4) Same thing but with a class that implements all the Logger methods
(is this called "duck typing"?), so all my code could work with a
standard Logger
5) Forget the logging module, it's not te be used the way i want to
use it
Nov 8 '08 #2

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

Similar topics

0
by: Nermin Brgulja | last post by:
Hi, I am using jdk1.4 Logger with a FileHandler for logging in a web application, and have two questions regarding logging: The first question is: I've created an Logger and mapped it to an...
0
by: Laszlo | last post by:
Hi I need a GL::Logger wich implements Class::Singleton to be a singleton and Log::Log4perl to can log amy message into a file. Here is the module source:...
2
by: Robert | last post by:
Hi all I have been trying to set up a framework with logging implemented using the built in Python logging module. For better or worse, I have decided to base the logger names on the module...
1
by: rodsatt | last post by:
Hi, This is my first post, and I got questions about logging. When something happen within an object, and if I would like to log the event, what would be a good way to do it? 1. I make the...
10
by: Gary Jefferson | last post by:
Suppose I have 3 modules that belong to a project, 'A', 'A.a' and 'B', and each module has its own logger, created with: module1logger = logging.getLogger('project.A') and module2logger =...
5
by: CedricCicada | last post by:
Greetings! I want to write messages into the Windows event log. I found sevicemanager, but the source is always "Python Service", and I'd like to be a bit more descriptive. Poking around on...
4
by: garyjefferson123 | last post by:
Suppose I have some sort of context variable that I want to appear in log messages. E.g.: logger = logging.getLogger("somelogger") class SomeOp: def __init__(self, ctx): self.ctx = ctx def...
2
by: DwBear75 | last post by:
I am hoping to find some simple examples of how to create a logger instance using smtphandler. I don't want to create a separate ini file. I just want to sent the smtphost, from, to right in the...
1
by: nagk9 | last post by:
Hi , I am using log4j in my application. I have the problem with log4j.properties file . It will automatically appends another logger file from the current logger which i am using for the...
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:
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
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?
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
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
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
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.