logging: my experience thus far. Be Careful With SMTPHandler!!

Discussion in 'Python' started by Pete Jereb, Oct 7, 2003.

  1. Pete Jereb

    Pete Jereb Guest

    Ok, I've managed to get the logging package to work, sort of. I'm
    writing a text parser, where data entry clerks can edit large,
    unwieldy and unforgiving textfiles that are VERY SENSITIVE as to where
    things are located, ie the decimal place MUST BE 15 spaces after the
    last word on the line. So I'm writing a backend, and a Microsoft
    Access guru is writing the gui. Once they edit the files by field,
    the corrected files are sent to a printer program. Now what I'm
    trying to do is separate out the blocks of text that are still funky,
    by scanning for data entry errors. This errorlist will then be
    emailed to the typist and they can see what they did wrong and try
    again.


    So first,

    import logging
    import logging.handlers

    next instantiate a logger:

    logger = logging.getLogger('mylog')

    I want to store the log in memory before I email it to the typist, and
    for now I want it to be able to hold maxint number of errorlistings:

    mem_hdlr = logging.handlers.MemoryHandler(sys.maxint)

    Assign mem_hdlr to logger:

    logger.addHandler(mem_hdlr)

    And sprinkle logger messages throughout the code:

    logger.info('subroutine x called')

    I want to send all errors in the mem_hdlr to the email_hdlr, which
    should email the errors to me, my assistant, and the typist, so we can
    all see what's going on:

    email_hdlr = logging.handlers.SMTPHandler('xxx.xxx.xxx.xx',
    '', to_list, 'autogen errorlog')

    xxx.xxx.xxx.xx is the address of the my SMTP server. followed by
    from, to_list is a list of email addresses to send the errors to, and
    last is the subject.

    So these last few lines of the program,

    mem_hdlr.setTarget(email_hdlr)
    mem_hdlr.close()

    supposedly, to the best of my reading comprehension, were to dump
    mem_hdlr's log into email_hdlr, which would then email the log to the
    listed recipients.

    Which is what happens except for one small detail. The errorlog is
    emailed to the recipients.

    One
    Line
    At
    A
    Time

    Which means I have 2,000 new emails as I type this, and the assistant
    and typist are going to be mighty surprised when they come in
    tomorrow! I'm just glad I took my supervisor off the testlist :)

    I'm getting really confused by the logging package. If I can't figure
    out how to use .logging to do what I need it to do I'll just use
    smtplib and write the errors to a string, and email the string. Oh
    well this is how I spent my day, hopefully this will be helpful to
    someone.
     
    Pete Jereb, Oct 7, 2003
    #1
    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. Replies:
    3
    Views:
    499
    Vinay Sajip
    May 1, 2007
  2. akonsu
    Replies:
    4
    Views:
    945
    Chris Withers
    Sep 30, 2009
  3. mynthon
    Replies:
    1
    Views:
    1,714
    Vinay Sajip
    Dec 6, 2009
  4. Nunya Business

    My toolbox, thus far...

    Nunya Business, Sep 23, 2007, in forum: Ruby
    Replies:
    1
    Views:
    144
    Ari Brown
    Sep 25, 2007
  5. surf
    Replies:
    5
    Views:
    566
    Dr.Ruud
    Feb 7, 2006
Loading...

Share This Page