logging question

Chuck cmedcoff at hotmail.com
Wed Oct 6 22:10:02 EDT 2004


> Each logger can have multiple handlers attached to it, with each of the
> handlers having their own threshold.  You can easily create a file
> handler, a stream (stdout) handler, and an email handler, all attached
> to your (root) logger.  Any logged messages should go to all of the
> attached handlers.  But if you, for example, give the email handler a
> threshold of 'critical', then 'info' and 'error' messages will go to the
> file and to stdout but won't get emailed.

Go it...

import logging

log = logging.getLogger("app.log")
fmt = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
h1 = logging.StreamHandler()
h1.setFormatter(fmt)
h2 = logging.FileHandler('.//app.log')
h2.setFormatter(fmt)
log.addHandler(h1)
log.addHandler(h2)





More information about the Python-list mailing list