Removing default logging handler (causes duplicate logging)

G

Gal Aviel

Hello All,

I want to add a logger to my application, then addHandler to it to log to a
special destination.

Unfortunately when I use logging.getLogger("my_logger") to create the new
logger, it apparently comes with a default handler that logs to STDOUT (or
STDERR?). When I add my special handler it works Ok, but still logs to terminal,
which I do not want.

The only way I found to remove the default handler is by using
'logger.removeHandler(logger.handlers[0])'.

Is there a more elegant solution that uses the logging API?

my setup: Python 2.5.1 on Linux Suse 9.

P.S.I am not using Basic config, just 'import logging' and then regular
logging.* calls.

Thanks in advance,
Gal Aviel.
 
G

Gerard Flanagan

Hello All,

I want to add a logger to my application, then addHandler to it to log to a
special destination.

Unfortunately when I use logging.getLogger("my_logger") to create the new
logger, it apparently comes with a default handler that logs to STDOUT (or
STDERR?). When I add my special handler it works Ok, but still logs to terminal,
which I do not want.

from docs:
------------------
getLogger( [name])

Return a logger with the specified name or, if no name is specified,
return a logger which is the root logger of the hierarchy.
------------------

so you should do 'root = getlogger()', then append your own logger to
the root.

Gerard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top