ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: Using logging module for conditional nested logs
by Jean-Michel Pichavant other posts by this author
Nov 5 2009 2:11AM messages near this date
Re: Using logging module for conditional nested logs | a is b
Reckoner wrote:
>  On Nov 4, 1:30 pm, Vinay Sajip <vinay_sa...@[...].uk> wrote:
>    
> > On Nov 4, 7:40 pm, Reckoner <recko...@[...].com> wrote:
> >
> >
> >
> >     
> >> I hope that made some sense.
> >>       
> > Not especially :-(
> >
> > Sorry I don't understand exactly what you mean, because I find your
> > terminology confusing. For example, "logger that is attached to foo2"
> > - loggers are not attached to functions. "It responds to the 'root'
> > logger" - what responds? What's meant by "respond"?
> >
> > Loggers correspond to specific code components in an application.
> > Normally these areas are modules and sometimes they're classes.
> >
> > You can certainly treat functions as areas but this will typically
> > become unwieldy in any sizeable application. It doesn't (in general)
> > make sense to have a specific logger for foo1 for use only when it's
> > called by foo2. These seem like anti-patterns to me.
> >
> > Handlers are attached to loggers to make events logged via those
> > loggers available to different audiences - via console, file, email
> > etc.
> >
> > If you want to log that foo1 is being called by foo2, you can do this.
> > For example, you could have a utility function which walks (a
> > sufficient part of) the call stack to see the function call hierarchy,
> > then log this as additional information (e.g. using the 'extra'
> > parameter to the logging call). You can attach Filters to loggers and
> > handlers which use this information to decide where and whether to
> > actually record the event.
> >
> > As well as the Python logging documentation, you may also find the
> > following link useful:
> >
> > http://plumberjack.blogspot.com/2009/09/python-logging-101.html
> >
> > Regards,
> >
> > Vinay Sajip
> >     
> 
>  I appreciate your patience, as I am new to this.
> 
>  Your comments have put me on the right track. I will look at the link
>  you specify.
> 
>  Thanks again.
>    

_foo2Logger = None

def foo2():
    global _foo2Logger
    _foo2Logger = whateverLogger
    foo1()


def foo1():
    foo1Logger = logging.getLogger(_foo2Logger.name + '.foo1') # this is 
how you can "attach" dynamically a logger to another
    foo1Logger.info('')



But for all the reasons expressed by Vinay, you don't want to do that.

Jean-Michel
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Reckoner
Vinay Sajip
Vinay Sajip
Reckoner
Jean-Michel Pichavant

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved