Removing default logging handler (causes duplicate logging)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gal Aviel

    #1

    Removing default logging handler (causes duplicate logging)

    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.getLogg er("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.removeH andler(logger.h andlers[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.

  • Gerard Flanagan

    #2
    Re: Removing default logging handler (causes duplicate logging)

    On Mar 4, 1:29 pm, Gal Aviel <galav...@yahoo .comwrote:
    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.getLogg er("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

    Comment

    Working...