Extending Logger
polettog at gmail.com
polettog at gmail.com
Fri Nov 7 13:58:38 EST 2008
On Nov 7, 12:17 am, Thomas Christensen <thom... at thomaschristensen.org>
wrote:
> polet... at gmail.com writes:
> > I took a look to the logging module which was quite sexy at a first
> > sight, but then i finally realized the following : the Logger class
> > can't be extended since a Logger is created only with getLogger (the
> > subclass can't call/shouldn't call Logger.__init__()).
> > So, did i miss something? or maybe there's no need to extend the
> > Logger class?
>
> Taken fromhttp://docs.python.org/library/logging.html:
>
> logging.getLoggerClass()
>
> Return either the standard Logger class, or the last class passed to
> setLoggerClass(). This function may be called from within a new
> class definition, to ensure that installing a customised Logger
> class will not undo customisations already applied by other
> code. For example:
>
> class MyLogger(logging.getLoggerClass()):
> # ... override behaviour here
>
> logging.setLoggerClass(klass)
>
> Tells the logging system to use the class klass when instantiating a
> logger. The class should define __init__() such that only a name
> argument is required, and the __init__() should call
> Logger.__init__(). This function is typically called before any
> loggers are instantiated by applications which need to use custom
> logger behavior.
>
> Thomas
Yes but in the other hand : http://docs.python.org/library/logging.html#logger-objects
"Note that Loggers are never instantiated directly, but always through
the module-level function logging.getLogger(name)."
More information about the Python-list
mailing list