Logging module gives duplicate log entries

Amit Khemka khemkaamit at gmail.com
Tue Aug 21 09:28:25 EDT 2007


On 8/21/07, Shiao <multiseed at gmail.com> wrote:
> Hi,
> I am getting duplicate log entries with the logging module.
>
> The following behaves as expected, leading to one log entry for each
> logged event:
>
> logging.basicConfig(level=logging.DEBUG, filename='/tmp/foo.log')
>
> But this results in two entries for each logged event:
>
> applog = logging.getLogger()
> applog.setLevel(logging.DEBUG)
> hdl = logging.FileHandler('/tmp/foo.log')
> applog.addHandler(hdl)
>

You need to remove the handler from the logging object

# remove the handler once you are done
applog.removeHandler(hdl)


Cheers,
amit.

----
Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in
Home Page: www.cse.iitd.ernet.in/~csd00377

Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.



More information about the Python-list mailing list