473,515 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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',
'p********@yahoo.com', 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.
Jul 18 '05 #1
0 3484

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1444
by: Samir Patel | last post by:
First of all, hats of on logging module in python 2.3. Very elegant... I have 2 questions regarding Handler class in logging: 1. SocketHandler: Can I send plain string instead of pickle binary. This will allow me to send a TCP log message to program written in other programming lang. 2. SMTPHandler: Is there any way to send an email
0
1381
by: Pete Jereb | last post by:
toaddrs = ('bob@bob.com', 'joe@joe.com', 'moe@moe.com') logger = logging.getLogger("mine") hdlr = logging.handlers.SMTPHandler('xyz.com', 'abc@xyz.com', toaddrs, 'errorlog') logger.addHandler(hdlr) logger.info('Testing error logger') hdlr.emit(?) what should I have instead of a ? in the above line to make this (or ANY .emit() work? docs...
3
1931
by: Andreas Jung | last post by:
I am trying to write a custom logger with a custom handler: class MyHandler(StreamHandler): pass class Logger: def __init__(self): self._l = logging.getLogger('someident') self._l.addHandler(MyHandler('/path/to/logfile'))
6
2196
by: Eric DeWall | last post by:
In trying to clean up the inevitable debug printing littered through some code, I started reading up on the 'logging' module. Browsing groups indicates that the design of the module is controversial but personally I'm very happy to see such a full-featured logger as part of the standard distribution. Here's my problem though (using 2.3.3) -...
1
1272
by: Peter Mott | last post by:
The documentation for SMTPHandler say "The toaddrs should be a list of strings without domain names (That's what the mailhost is for)." which does not seem to be correct. The toaddr should be a list of strings like 'john@somewhere.com'. Peter
2
2191
by: chuck | last post by:
I want to create two different loggers so that users see one output (e.g. no exception/stack traces) and others (e.g support staff) that does see stack traces via email. The code below is close but I still get console output on the email logger from the "root" logger. How do I get rid of it? import logging import logging.handlers
10
2642
by: Baurzhan Ismagulov | last post by:
Hello all, I want that each module has its own logger. I've defined the following config file: keys=f01 keys=console
3
3088
by: james.p.news | last post by:
I'm new to Python, but I've been thrown into coding a pretty complicated regression testing script. I need to email the log of the daily test to the code owners. I thought I could use SMTPHandler for this, but our email system requires authentication. I have not been able to figure out how to log in using SMTPHandler. I found the...
1
2602
by: arunairs | last post by:
Hi, Using the EnterpriseLibrary 4.0, is it possible to Log the method name in the log file. I have it cofigured thus: <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true"> <listeners>
0
7273
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7181
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7570
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5105
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3256
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3246
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1615
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
480
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.