logging question

Discussion in 'Python' started by Guest, Oct 7, 2004.

  1. Guest

    Guest Guest

    I going through my first attempt at using the new logging facilities. I
    would like to have log output go to both a file and std error and perhaps
    email as well. Is there a handler that allows this sort of multiple outputs
    capture or will a custom handler have to be written?
    Guest, Oct 7, 2004
    #1
    1. Advertising

  2. Guest

    Jeff Shannon Guest

    wrote:

    >I going through my first attempt at using the new logging facilities. I
    >would like to have log output go to both a file and std error and perhaps
    >email as well. Is there a handler that allows this sort of multiple outputs
    >capture or will a custom handler have to be written?
    >
    >


    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.

    Jeff Shannon
    Technician/Programmer
    Credit International
    Jeff Shannon, Oct 7, 2004
    #2
    1. Advertising

  3. Guest

    Chuck Guest

    > 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)
    Chuck, Oct 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    0
    Views:
    941
    Stefan Siegl
    Aug 27, 2003
  2. janne
    Replies:
    0
    Views:
    9,448
    janne
    Sep 10, 2004
  3. Christoph Haas
    Replies:
    0
    Views:
    432
    Christoph Haas
    Jun 12, 2006
  4. Christoph Haas
    Replies:
    1
    Views:
    441
    Vinay Sajip
    Jun 14, 2006
  5. johnny
    Replies:
    1
    Views:
    625
    Dennis Lee Bieber
    Dec 12, 2006
Loading...

Share This Page