From efe2187bb567f6515c5f31dda3ac77ea0dbb4804 Mon Sep 17 00:00:00 2001 From: fkrone Date: Sat, 28 Mar 2015 19:23:49 +0100 Subject: [PATCH] Logging for cron job does now work to syslog if defined so in the config file (previously it thought it should write to a file called 'syslog' instead of the real syslog) --- gpg-mailgate-web/cron.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gpg-mailgate-web/cron.py b/gpg-mailgate-web/cron.py index c58ef6f..bccac72 100644 --- a/gpg-mailgate-web/cron.py +++ b/gpg-mailgate-web/cron.py @@ -24,14 +24,18 @@ import GnuPG import MySQLdb import smtplib import markdown +import syslog from email.MIMEText import MIMEText from email.mime.multipart import MIMEMultipart def appendLog(msg): - if cfg.has_key('logging') and cfg['logging'].has_key('file'): - log = open(cfg['logging']['file'], 'a') - log.write(msg + "\n") - log.close() + if 'logging' in cfg and 'file' in cfg['logging']: + if cfg['logging'].get('file') == "syslog": + syslog.syslog(syslog.LOG_INFO | syslog.LOG_MAIL, msg) + else: + logfile = open(cfg['logging']['file'], 'a') + logfile.write(msg + "\n") + logfile.close() def send_msg( mailsubject, messagefile, recipients = None ): mailbody = file( cfg['cron']['mail_templates'] + "/" + messagefile).read()