[IPython-dev] iplogging suggestions added
Sat Dec 11 19:19:15 CST 2010
On 2010-12-11 18:07 , Omar Andrés Zapata Mesa wrote:
> Hi Robert.
> The solution was create a class IpLogger that inherit from logging.Logger
> the new code us in repo.
I'm sorry, but I think you misunderstood my point. You should not add Handlers
or Formatters inside a library (except for the NullHandler), no matter how you
accomplish this. The decision of what messages get displayed and how they get
displayed must be left up to the application author (to set the defaults) and
the application user (possibly overriding the defaults), not the library author.
Please reread the section of the logging documentation I pointed out:
My recommendation is to provide the following:
# Provide the ColorFormatter just as you have it.
FORMAT = ...
def emit(self, record):
""" Provide a logger with a default NullHandler for use within the IPython
logger = logging.getLogger(name)
In each module that needs to do logging, you will do the following:
from IPython.utils.iplogging import get_logger
logger = get_logger(__name__)
That's it. No more configuration there. You must configure logging exactly once
at the application level. As Brian suggestion, a Configurable is probably a good
way to organize this since you want the application authors to provide a default
but allow users to override this. Please see the documentation for the variety
of ways one can configure logging:
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the IPython-dev