On Mon, Dec 13, 2010 at 9:47 AM, Bobby <[email protected]> wrote:
> I thought that import set up a library of functions and classes for me
> to call, but I dont understand how it knows what I have configured.
>
> The line I am referring to in the documentation is
> http://docs.python.org/library/logging.html
> 15.7.4. Module-Level Functions
>
> logging.getLogger([name])
>
> **All calls to this function with a given name return the same logger
> instance. This means that logger instances never need to be passed
> between different parts of an application.**
>
> I have been working with python and pylons for about 2 months now, so
> am still very new.
>
> I look forward to participating in the pylons community.
>
> Thank you in advance for any help on this matter.

Following up on programmer.py's response, Paste Deploy (i.,e., "paster
serve") calls ``logging.config.fileConfig(INI_FILE)``  for you. That's
how the logging configuration in development.ini gets initialized.

In Pylons it's customary for every module to contain the following global:

log = logging.getLogger(__name__)

This returns a logger with the same name as the module. That way the
person running the program can quickly find the module that produced a
log message, and hopefully there's only one line in that module with
that wording in the log message. Some applications prefer shorter or
more specific logger names, but the __name__ standard provides a
convenient baseline to start from.

The logging module keeps a central registry of all loggers, so at any
time you can call "getLogger" to obtain the one you want. That's what
it means by, you don't have to pass log objects around from function
to function.

Still, in some specialized cases it can be useful to write a generic
lib function that takes a log object or even a log method (e.g.,
``log.warn``) as an argument, to specify where to log messages to. For
instance, if one routine is producing one kind of object, and another
routine is producing another kind of object, but both routines are
calling the same function, you may want each routine to pass a logger
whose name indicates which kind of object is being created.

-- 
Mike Orr <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to