473,666 Members | 2,107 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.handler s

next instantiate a logger:

logger = logging.getLogg er('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.handler s.MemoryHandler (sys.maxint)

Assign mem_hdlr to logger:

logger.addHandl er(mem_hdlr)

And sprinkle logger messages throughout the code:

logger.info('su broutine 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.handler s.SMTPHandler(' xxx.xxx.xxx.xx' ,
'p********@yaho o.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.setTar get(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 3491

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

Similar topics

0
1450
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
1387
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 say a record, but I can't seem to locate this
3
1947
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
2206
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) - I'm trying to write some reusable classes that _optionally_ use the logging module. So a class...
1
1280
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
2207
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
2662
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
3098
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 following post on comp.lang.python: ...
1
2613
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
8448
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6198
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1776
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.