[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r16932: {projects} Patch from kaner: Rewrote logging, using python logging modu (in projects/gettor: . i18n/de i18n/en)
Author: ioerror
Date: 2008-09-21 13:39:09 -0400 (Sun, 21 Sep 2008)
New Revision: 16932
Modified:
projects/gettor/gettor.py
projects/gettor/gettor_config.py
projects/gettor/gettor_log.py
projects/gettor/i18n/de/gettor_de.po
projects/gettor/i18n/en/gettor_en.po
Log:
Patch from kaner:
Rewrote logging, using python logging module instead of our own (cruft--)
This enables us to have different logging levels for the future and also to use other logging facilities with ease.
Updated i18n directory.
Modified: projects/gettor/gettor.py
===================================================================
--- projects/gettor/gettor.py 2008-09-21 01:03:00 UTC (rev 16931)
+++ projects/gettor/gettor.py 2008-09-21 17:39:09 UTC (rev 16932)
@@ -75,19 +75,20 @@
options, arguments = gettor_opt.parseOpts()
conf = gettor_config.gettorConf(options.configfile)
- log = gettor_log.gettorLogger()
+ logger = gettor_log.gettorLogger()
+ log = logger.getLogger()
logLang = conf.getLocale()
switchLocale(logLang)
rawMessage = gettor_requests.getMessage()
parsedMessage = gettor_requests.parseMessage(rawMessage)
if not parsedMessage:
- log.log(_("No parsed message. Dropping message."))
+ log.info(_("No parsed message. Dropping message."))
exit(1)
signature = False
signature = gettor_requests.verifySignature(rawMessage)
- log.log(_("Signature is: %s") % str(signature))
+ log.info(_("Signature is: %s") % str(signature))
replyTo = False
srcEmail = conf.getSrcEmail()
@@ -100,7 +101,7 @@
#
distDir = conf.getDistDir()
if not os.path.isdir(distDir):
- log.log(_("Sorry, %s is not a directory.") % distDir)
+ log.info(_("Sorry, %s is not a directory.") % distDir)
exit(1)
packageList = {
@@ -114,10 +115,10 @@
for key, val in packageList.items():
# Remove invalid packages
if not os.access(val, os.R_OK):
- log.log(_("Warning: %s not accessable. Removing from list." % val))
+ log.info(_("Warning: %s not accessable. Removing from list.") % val)
del packageList[key]
if len(packageList) < 1:
- log.log(_("Sorry, your package list is unusable."))
+ log.info(_("Sorry, your package list is unusable."))
exit(1)
# XXX TODO: Ensure we have a proper replyTO or bail out (majorly malformed mail).
@@ -133,11 +134,11 @@
previouslyHelped = gettor_blacklist.blackList(replyTo)
if not replyTo:
- log.log(_("No help dispatched. Invalid reply address for user."))
+ log.info(_("No help dispatched. Invalid reply address for user."))
exit(1)
if not signature and previouslyHelped:
- log.log(_("Unsigned messaged to gettor by blacklisted user dropped."))
+ log.info(_("Unsigned messaged to gettor by blacklisted user dropped."))
exit(1)
if not signature and not previouslyHelped:
@@ -161,11 +162,11 @@
""")
switchLocale(logLang)
gettor_responses.sendHelp(message, srcEmail, replyTo)
- log.log(_("Unsigned messaged to gettor. We issued some help about using DKIM."))
+ log.info(_("Unsigned messaged to gettor. We issued some help about using DKIM."))
exit(0)
if signature:
- log.log(_("Signed messaged to gettor."))
+ log.info(_("Signed messaged to gettor."))
try:
package = gettor_requests.parseRequest(parsedMessage, packageList)
@@ -173,7 +174,7 @@
package = None
if package != None:
- log.log(_("Package: %s selected.") % str(package))
+ log.info(_("Package: %s selected.") % str(package))
message = _("""
Here's your requested software as a zip file. Please unzip the
package and verify the signature.
@@ -190,5 +191,5 @@
message.append(_("Please send me another email. It only needs a single package name anywhere in the body of your email.\n"))
switchLocale(logLang)
gettor_responses.sendHelp(''.join(message), srcEmail, replyTo)
- log.log(_("Signed messaged to gettor. We issued some help about proper email formatting."))
+ log.info(_("Signed messaged to gettor. We issued some help about proper email formatting."))
exit(0)
Modified: projects/gettor/gettor_config.py
===================================================================
--- projects/gettor/gettor_config.py 2008-09-21 01:03:00 UTC (rev 16931)
+++ projects/gettor/gettor_config.py 2008-09-21 17:39:09 UTC (rev 16932)
@@ -37,6 +37,7 @@
logFile: If 'file' logging is chosen, log to this file
logSubSystem: This has to be one of the following strings:
'nothing': Nothing is logged anywhere (Recommended)
+ 'stdout': Log to stdout
'syslog': Logmessages will be written to syslog
'file': Logmessages will be written to a file (Not that
this needs the 'logFile' option in the config file
Modified: projects/gettor/gettor_log.py
===================================================================
--- projects/gettor/gettor_log.py 2008-09-21 01:03:00 UTC (rev 16931)
+++ projects/gettor/gettor_log.py 2008-09-21 17:39:09 UTC (rev 16932)
@@ -1,9 +1,19 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
-gettor may log information, this is how we handle that logging requirement.
-A user may log to syslog, a file, stdout or not at all.
-The user can choose one of those four options in a configuration file.
+ gettor_log.py - gettor logging configuration
+
+ Copyright (c) 2008, Jacob Appelbaum <jacob@xxxxxxxxxxxxx>,
+ Christian Fromme <kaner@xxxxxxxxxx>
+
+ This is Free Software. See LICENSE for license information.
+
+ gettor may log information, this is how we handle that logging requirement.
+ A user may log to 'syslog', a 'file', 'stdout' or 'nothing'.
+ The user can choose one of those four options in a configuration file.
+
+ Note that this module will silently fall back to 'nothing' if anything is
+ minconfigured. Might be harder to debug, but is safer for now.
'''
import os
@@ -11,57 +21,62 @@
from time import gmtime, strftime
import ConfigParser
import syslog
-from gettor_config import gettorConf
+import logging
+import gettor_config
+from logging import handlers
+# Leave this to INFO for now
+loglevel = logging.INFO
+
class gettorLogger:
'''
A configurable logging system for gettor.
'''
- config = gettorConf()
- logger = config.getLogSubSystem()
- logfile = config.getLogFile()
- logfd = None
- pid = str(os.getpid())
- logPrefix = "gettor (pid " + pid + ") "
- def _init_(self):
- # parse the configuration file so we know how we're running
- if logger == "file":
+ format = '%(asctime)-15s (%(process)d) %(message)s'
+
+ def __init__(self):
+ self.config = gettor_config.gettorConf()
+ self.logger = logging.getLogger('gettor')
+ self.logger.setLevel(loglevel)
+ self.logSubSystem = self.config.getLogSubSystem()
+
+ if self.logSubSystem == "stdout":
+ handler = logging.StreamHandler()
+ elif self.logSubSystem == "file":
+ # Silently fail if things are misconfigured
+ self.logFile = self.config.getLogFile()
try:
- self.logfd = open(logfile, "a+")
+ if os.access(os.path.dirname(self.logFile), os.W_OK):
+ handler = logging.FileHandler(self.logFile)
+ else:
+ self.logSubSystem = "nothing"
except:
- self.logfd = None
-
- def _del_(self):
- if logger == "file" and self.logfd == None:
- self.logfd.close()
-
- def log(self, message):
- # Syslog does not need a timestamp
- if self.logger == "syslog":
- now = ""
+ self.logSubSystem = "nothing"
+ elif self.logSubSystem == "syslog":
+ handler = logging.handlers.SysLogHandler(address="/dev/log")
else:
- now = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
+ # Failsafe fallback
+ self.logSubSystem = "nothing"
- message = self.logPrefix + now + " : "+ message
+ # If anything went wrong or the user doesn't want to log
+ if self.logSubSystem == "nothing":
+ handler = logging.FileHandler("/dev/null")
- # By default, we'll just drop the message
- if self.logger == "nothing":
- return True
+ formatter = logging.Formatter(fmt=self.format)
+ handler.setFormatter(formatter)
+ self.logger.addHandler(handler)
- # Other options for logging the message follow
- elif self.logger == "syslog":
- syslog.syslog(message)
-
- elif self.logger == "file":
- self.logfd.write(message)
+ def getLogSubSystem(self):
+ return self.logSubSystem
- elif self.logger == "stdout":
- print message
+ def getLogger(self):
+ return self.logger
if __name__ == "__main__" :
l = gettorLogger()
print "This is the logging module. You probably do not want to call it by hand."
print "We'll send a test logging message now with the following subsystem: " + \
- str(l.logger)
- l.log("I'm a logger, logging!")
+ l.getLogSubSystem()
+ log = l.getLogger()
+ log.info("I'm a logger, logging!")
Modified: projects/gettor/i18n/de/gettor_de.po
===================================================================
--- projects/gettor/i18n/de/gettor_de.po 2008-09-21 01:03:00 UTC (rev 16931)
+++ projects/gettor/i18n/de/gettor_de.po 2008-09-21 17:39:09 UTC (rev 16932)
@@ -15,23 +15,35 @@
"Generated-By: pygettext.py 1.5\n"
-#: gettor.py:75
+#: gettor.py:86
msgid "No parsed message. Dropping message."
msgstr "Konnte die Nachricht nicht parsen. Loesche Nachricht."
-#: gettor.py:80
+#: gettor.py:91
msgid "Signature is: %s"
msgstr "Die Signatur ist: %s"
-#: gettor.py:107
+#: gettor.py:104
+msgid "Sorry, %s is not a directory."
+msgstr "Achtung, %s ist kein Verzeichnis."
+
+#: gettor.py:118
+msgid "Warning: %s not accessable. Removing from list."
+msgstr "Achtung: %s unbenutzbar. Entferne von Liste."
+
+#: gettor.py:121
+msgid "Sorry, your package list is unusable."
+msgstr "Die Paketliste ist unbenutzbar."
+
+#: gettor.py:137
msgid "No help dispatched. Invalid reply address for user."
-msgstr "Keine Hilfe versendet. Die Antwortadresse des Users ist ungueltig."
+msgstr "Keine Hilfe versandt. Ungueltige Reply Adresse."
-#: gettor.py:111
+#: gettor.py:141
msgid "Unsigned messaged to gettor by blacklisted user dropped."
-msgstr "gettor: Unsignierte Nachricht an gettor von einem blacklisted User geloescht."
+msgstr "Unsignierte Nachricht blacklisted und verworfen."
-#: gettor.py:117
+#: gettor.py:148
msgid ""
"\n"
"Hello! This is the \"get tor\" robot.\n"
@@ -64,19 +76,19 @@
"den naechsten Tag.)\n"
" "
-#: gettor.py:133
+#: gettor.py:165
msgid "Unsigned messaged to gettor. We issued some help about using DKIM."
msgstr "Unsignierte Nachricht. Hilfe zu DKIM versandt."
-#: gettor.py:137
+#: gettor.py:169
msgid "Signed messaged to gettor."
msgstr "Signierte Nachricht empfangen."
-#: gettor.py:145
+#: gettor.py:177
msgid "Package: %s selected."
msgstr "Paket: %s gewaehlt."
-#: gettor.py:146
+#: gettor.py:178
msgid ""
"\n"
"Here's your requested software as a zip file. Please unzip the \n"
@@ -88,59 +100,59 @@
"entpacken Sie diese und verifizieren Sie die digitale Signatur.\n"
" "
-#: gettor.py:153
+#: gettor.py:186
msgid "Hello, I'm a robot. "
msgstr "Hallo, Ich bin der automatische Mail-Versandt"
-#: gettor.py:154
+#: gettor.py:187
msgid ""
"Your request was not understood. Please select one of the following package names:\n"
msgstr ""
"Ihre Anfrage war nicht zu verstehen. Bitte waehlen Sie eines der folgenden Paketnamen:\n"
-#: gettor.py:158
+#: gettor.py:191
msgid ""
"Please send me another email. It only needs a single package name anywhere in the body of your email.\n"
msgstr ""
"Bitte senden Sie mir eine weitere Email. Schreiben Sie darin lediglich den Paketnamen.\n"
-#: gettor.py:160
+#: gettor.py:194
msgid "Signed messaged to gettor. We issued some help about proper email formatting."
msgstr "Signierte Nachricht empfangen. Hilfe ueber das richtige formatieren von Email versandt."
-#: gettor_requests.py:65
+#: gettor_requests.py:75
msgid "Fetching raw message."
msgstr "Hole Nachricht im Raw-Format."
-#: gettor_requests.py:68
+#: gettor_requests.py:78
msgid "Verifying signature of message."
msgstr "Verifiziere Signatur der Nachricht."
-#: gettor_requests.py:70
+#: gettor_requests.py:80
msgid "Parsing Message."
msgstr "Verarbeite Nachricht."
-#: gettor_requests.py:72
+#: gettor_requests.py:82
msgid "Parsing reply."
msgstr "Verarbeite Antwort."
-#: gettor_requests.py:74
+#: gettor_requests.py:44
msgid "Parsing package request."
msgstr "Verarbeite Paketanfrage."
-#: gettor_requests.py:81
+#: gettor_requests.py:91
msgid "The signature status of the email is: %s"
msgstr "Der Signatur-Status dieser Email ist: %s"
-#: gettor_requests.py:82
+#: gettor_requests.py:92
msgid "The email requested the following reply address: %s"
msgstr "Die verlangte Email hat folgende Antwortadresse: %s"
-#: gettor_requests.py:83
+#: gettor_requests.py:93
msgid "It looks like the email requested the following package: %s"
msgstr "Es sieht aus als wuerde die Email folgendes Paket anfodern: %s"
-#: gettor_requests.py:84
+#: gettor_requests.py:94
msgid "We would select the following package file: "
msgstr "Folgendes Paket wird ausgeaehlt: "
Modified: projects/gettor/i18n/en/gettor_en.po
===================================================================
--- projects/gettor/i18n/en/gettor_en.po 2008-09-21 01:03:00 UTC (rev 16931)
+++ projects/gettor/i18n/en/gettor_en.po 2008-09-21 17:39:09 UTC (rev 16932)
@@ -15,23 +15,35 @@
"Generated-By: pygettext.py 1.5\n"
-#: gettor.py:75
+#: gettor.py:86
msgid "No parsed message. Dropping message."
msgstr ""
-#: gettor.py:80
+#: gettor.py:91
msgid "Signature is: %s"
msgstr ""
-#: gettor.py:107
+#: gettor.py:104
+msgid "Sorry, %s is not a directory."
+msgstr ""
+
+#: gettor.py:118
+msgid "Warning: %s not accessable. Removing from list."
+msgstr ""
+
+#: gettor.py:121
+msgid "Sorry, your package list is unusable."
+msgstr ""
+
+#: gettor.py:137
msgid "No help dispatched. Invalid reply address for user."
msgstr ""
-#: gettor.py:111
+#: gettor.py:141
msgid "Unsigned messaged to gettor by blacklisted user dropped."
msgstr ""
-#: gettor.py:117
+#: gettor.py:148
msgid ""
"\n"
"Hello! This is the \"get tor\" robot.\n"
@@ -50,19 +62,19 @@
" "
msgstr ""
-#: gettor.py:133
+#: gettor.py:165
msgid "Unsigned messaged to gettor. We issued some help about using DKIM."
msgstr ""
-#: gettor.py:137
+#: gettor.py:169
msgid "Signed messaged to gettor."
msgstr ""
-#: gettor.py:145
+#: gettor.py:177
msgid "Package: %s selected."
msgstr ""
-#: gettor.py:146
+#: gettor.py:178
msgid ""
"\n"
"Here's your requested software as a zip file. Please unzip the \n"
@@ -70,57 +82,57 @@
" "
msgstr ""
-#: gettor.py:153
+#: gettor.py:186
msgid "Hello, I'm a robot. "
msgstr ""
-#: gettor.py:154
+#: gettor.py:187
msgid ""
"Your request was not understood. Please select one of the following package names:\n"
msgstr ""
-#: gettor.py:158
+#: gettor.py:191
msgid ""
"Please send me another email. It only needs a single package name anywhere in the body of your email.\n"
msgstr ""
-#: gettor.py:160
+#: gettor.py:194
msgid "Signed messaged to gettor. We issued some help about proper email formatting."
msgstr ""
-#: gettor_requests.py:65
+#: gettor_requests.py:75
msgid "Fetching raw message."
msgstr ""
-#: gettor_requests.py:68
+#: gettor_requests.py:78
msgid "Verifying signature of message."
msgstr ""
-#: gettor_requests.py:70
+#: gettor_requests.py:80
msgid "Parsing Message."
msgstr ""
-#: gettor_requests.py:72
+#: gettor_requests.py:82
msgid "Parsing reply."
msgstr ""
-#: gettor_requests.py:74
+#: gettor_requests.py:84
msgid "Parsing package request."
msgstr ""
-#: gettor_requests.py:81
+#: gettor_requests.py:91
msgid "The signature status of the email is: %s"
msgstr ""
-#: gettor_requests.py:82
+#: gettor_requests.py:92
msgid "The email requested the following reply address: %s"
msgstr ""
-#: gettor_requests.py:83
+#: gettor_requests.py:93
msgid "It looks like the email requested the following package: %s"
msgstr ""
-#: gettor_requests.py:84
+#: gettor_requests.py:94
msgid "We would select the following package file: "
msgstr ""