X-Git-Url: https://git.sthu.org/?p=smailq.git;a=blobdiff_plain;f=smailq;h=1ab3afc95bba77ccf8a79e4e6d4b0c68c1a1f3ec;hp=d719d43a283e916d2a15299ba3a5218242eee328;hb=5b83ca873f1dc9117a9b3590f0aa07fe2806fce9;hpb=4fbe052b37ddedb7ae917916f6670ce6242e3b01 diff --git a/smailq b/smailq index d719d43..1ab3afc 100755 --- a/smailq +++ b/smailq @@ -5,7 +5,7 @@ __author__ = "Stefan Huber" __copyright__ = "Copyright 2013" __license__ = "LGPL-3" -__version__ = "1.0" +__version__ = "1.2" from contextlib import contextmanager @@ -20,6 +20,7 @@ import subprocess import sys import time import socket +import syslog verbose = False @@ -302,13 +303,19 @@ class MailQueue: def log(conf, msg, id=None): """Write message to log file""" + # Prepend ID to msg + if id is not None: + msg = ("ID %s: " % id) + msg + + if conf.getlogdir() == 'syslog': + syslog.syslog(msg) + return + fn = conf.getlogdir() + "/smailq.log" with open(fn, 'a') as f: fcntl.lockf(f, fcntl.LOCK_EX) - # Prepend ID to msg - if id is not None: - msg = ("ID %s: " % id) + msg + # Prepend time to msg msg = time.strftime("%Y-%m-%d %H:%M:%S: ", time.localtime()) + msg @@ -383,7 +390,7 @@ COMMANDS: OPTIONS: -C, --config=FILE - Use the given configuration file instead of "$HOME/.smailq.conf". + Use the given configuration file. -q, --quiet Do not print info messages. @@ -427,7 +434,7 @@ if __name__ == "__main__": assert(False) except getopt.GetoptError as e: - printerr("Error parsing arguments:", e) + printerr("Error parsing arguments: " + str(e)) usage() sys.exit(os.EX_USAGE) @@ -444,12 +451,14 @@ if __name__ == "__main__": printerr("Data directory does not exist: " + conf.getdatadir()) sys.exit(os.EX_IOERR) - if not os.path.isdir(conf.getlogdir()): - printerr("Log directory does not exist: " + conf.getlogdir()) - sys.exit(os.EX_IOERR) + if conf.getlogdir() == 'syslog': + syslog.openlog('smailq', 0, syslog.LOG_MAIL) + elif not os.path.isdir(conf.getlogdir()): + printinfo('Creating logdir: ' + conf.getlogdir()) + os.mkdir(conf.getlogdir()) except Exception as e: - printerr("Error reading config file:", e) + printerr("Error reading config file: " + str(e)) sys.exit(os.EX_IOERR) try: