By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 759 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
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:


And sprinkle logger messages throughout the code:'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('',
'p********', to_list, 'autogen errorlog') 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,


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.


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
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.