Logging module: problem with some mapping keys

Tekkaman simone.leo at gmail.com
Thu Dec 14 09:17:39 EST 2006


sim.sim wrote:
> Hi, i've check documentation, and found that logging.basicConfig takes
> no arguments (probably we have different versions of logging package),

Your Python version is < 2.4. Now basicConfig takes optional keyword
args:

basicConfig([**kwargs])
Does basic configuration for the logging system by creating a
StreamHandler with a default Formatter and adding it to the root
logger. The functions debug(), info(), warning(), error() and
critical() will call basicConfig() automatically if no handlers are
defined for the root logger.

In my real application (not the small test script!) This behaviour is
very useful since I can call basicConfig only once in the main file and
then all I have to do in the other files is:

import logging
self.logger = logging.getLogger("myClass")

Everything works smoothly except for not being able to get file and
line number info.

> and i've never used it.
>
> just try this:
>
>
> fileName = 'testlog.log'
> logName = 'LOG'
> iHandler = logging.FileHandler(fileName)
> iHandler.setFormatter(
> logging.Formatter("%(levelname)-8s|%(asctime)s|%(pathname)s,%(name)s,
> line %(lineno)s|%(message)s") )
>
> iLog = logging.getLogger(logName)
> iLog.addHandler(iHandler)
> iLog.setLevel(logging.DEBUG)
>
> iLog.info('hello logging')
>
>
>
> it gives me:
>
> INFO    |2006-12-13 19:57:33,575|test.py,LOG, line 12|hello logging
>
>
> On 13 Dec., 19:02, "Tekkaman" <simone.... at gmail.com> wrote:
> > I'm getting a strange behaviour from the "pathname" and "lineno"
> > formatter mapping keys. Instead of my file and my line number I get:
> >
> > /usr/lib/python2.4/logging/__init__.py
> >
> > as the file, and 1072 as the line number. I set up my config as
> > follows:
> >
> > logBaseConf = {
> >         'level'   : logging.DEBUG,
> >         'format'  : "%(levelname)-8s|%(asctime)s|%(pathname)s,
> > %(name)s, line %(lineno)s|%(message)s",
> >         'datefmt ': '%d %b %Y, %H:%M:%S',
> >         'filename': 'logtest.log',
> >         'filemode': 'a'
> >         }
> > logging.basicConfig(**logBaseConf)
> >
> > I'm not using any executable-generating tools such as cx_Freeze or
> > Psyco. In fact, I'm getting this error on a very basic script with the
> > specific purpose of testing the logging module capabilities.
> >
> > Thanks in advance for any contribution.
> > 
> > T.
> 
> --
> Maksim Kasimov




More information about the Python-list mailing list