Update of /cvsroot/tmda/tmda/TMDA
In directory usw-pr-cvs1:/tmp/cvs-serv5631/TMDA
Modified Files:
ChangeLog Defaults.py
Added Files:
MessageLogger.py
Log Message:
Move incoming logging code from tmda-rfilter's logit() into a new
module, MessageLogger. This module is now used to provide both
incoming and outgoing logging (via LOGFILE_OUTGOING) in a consistent
format.
--- NEW FILE ---
# -*- python -*-
#
# Copyright (C) 2001,2002 Jason R. Mastaler <jason@xxxxxxxxxxxx>
#
# This file is part of TMDA.
#
# TMDA is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of this license should
# be included in the file COPYING.
#
# TMDA is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with TMDA; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
Log statistics about incoming or outgoing messages to a file.
"""
import Util
class MessageLogger:
def __init__(self, logfile, headers, **vardict):
"""
logfile is the full path to the logfile.
headers is an rfc822.Message instance.
vardict is a dictionary containing an indefinite number of
keyword arguments.
"""
self.headers = headers
self.vardict = vardict
self.logfile = logfile
self.log = open(self.logfile, 'a')
def write(self):
"""
Write a log entry for this message in a common format.
Date: (timestamp)
Sndr: (envelope sender address if different from From:)
From: (From: header)
Rept: (Reply-To: header)
To: (envelope recipient address)
Subj: (Subject: header)
Actn: (message trigger and size of message)
"""
self.__writeline('Date', Util.unixdate())
envsender = self.vardict.get('envsender', None)
if (envsender
and self.headers.getaddr('from')[1] != envsender):
self.__writeline('Sndr', envsender)
From = self.headers.getheader('from')
if From:
self.__writeline('From', From)
ReplyTo = self.headers.getheader('reply-to')
if ReplyTo:
self.__writeline('Rept', ReplyTo)
self.__writeline('To', self.vardict.get('envrecip'))
self.__writeline('Subj', self.headers.getheader('subject', 'None'))
Action = self.vardict.get('action_msg')
sizestr = '(%s)' % self.vardict.get('msg_size')
wsbuf = 72 - len(Action) - len(sizestr)
Action = Action + ' '*wsbuf + sizestr # 78 chars max
self.__writeline('Actn', Action)
self.__close()
def __writeline(self, name, value):
self.log.write('%s: %s\n' % (name.rjust(4), value))
def __close(self):
self.log.write('\n')
self.log.close()
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.220
retrieving revision 1.221
diff -u -r1.220 -r1.221
--- ChangeLog 8 Aug 2002 04:11:50 -0000 1.220
+++ ChangeLog 8 Aug 2002 16:49:46 -0000 1.221
@@ -1,3 +1,9 @@
+2002-08-08 Jason R. Mastaler <jasonrm@xxxxxxxxxxxxxxxxxxxxxxxxxx>
+
+ * MessageLogger.py: New module.
+
+ * Defaults.py (LOGFILE_OUTGOING): New variable.
+
2002-08-07 Tim Legant <tim@xxxxxxxxxxx>
* FilterParser.py (_FilterFile): New class to hold per-file data.
Index: Defaults.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Defaults.py,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -r1.136 -r1.137
--- Defaults.py 30 Jul 2002 03:58:57 -0000 1.136
+++ Defaults.py 8 Aug 2002 16:49:46 -0000 1.137
@@ -728,21 +728,33 @@
# Filename which uncaught exceptions should be written to.
#
# Example:
-# LOGFILE_DEBUG = "/path/to/tmda_debug.log"
+# LOGFILE_DEBUG = "/path/to/logs/tmda.debug"
#
# No default.
if not vars().has_key('LOGFILE_DEBUG'):
LOGFILE_DEBUG = None
# LOGFILE_INCOMING
-# Filename which delivery summaries should be written to.
+# Filename which incoming delivery (i.e, tmda-filter) summaries should
+# be written to.
#
# Example:
-# LOGFILE_INCOMING = "/path/to/tmda_incoming.log"
+# LOGFILE_INCOMING = "/path/to/logs/tmda.in"
#
# No default.
if not vars().has_key('LOGFILE_INCOMING'):
LOGFILE_INCOMING = None
+
+# LOGFILE_OUTGOING
+# Filename which outgoing message (i.e, tmda-sendmail) summaries
+# should be written to.
+#
+# Example:
+# LOGFILE_OUTGOING = "/path/to/logs/tmda.out"
+#
+# No default.
+if not vars().has_key('LOGFILE_OUTGOING'):
+ LOGFILE_OUTGOING = None
# LOCALDATE
# Set this variable to 0 if you want TMDA to generate ``Date:''
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs
|