From ae9ddd306161a995b213d31003971fa20a15791c Mon Sep 17 00:00:00 2001 From: Martin Abente Date: Fri, 25 Mar 2011 17:56:23 +0000 Subject: Add custom log to mailer --- diff --git a/config.ini.example b/config.ini.example index eaf929d..a6214fc 100644 --- a/config.ini.example +++ b/config.ini.example @@ -18,3 +18,4 @@ smtp_user: feedbackreporter smtp_password: 123456 smtp_server: smtp.activitycentral.com smtp_port: 25 +log_path: /home/tch/Devel/feedback-server/mailer.log diff --git a/reports_mailer.py b/reports_mailer.py index ac042c8..8b61840 100755 --- a/reports_mailer.py +++ b/reports_mailer.py @@ -20,6 +20,7 @@ import sys import json import time import smtplib +import logging from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from ConfigParser import ConfigParser @@ -145,11 +146,11 @@ def check_reports(): try: report_info = json.loads(report_data) except Exception, e: - print 'Error while parsing %s: %s' % (report_info_path, str(e)) + logging.info('Error while parsing %s: %s' % (report_info_path, str(e))) continue if len(report_info.keys()) <= 0: - print 'Empty report %s.' % report_info_path + logging.info('Empty report %s.' % report_info_path) continue body = generate_body(report_info, report_info_path) @@ -159,21 +160,25 @@ def check_reports(): try: send_email(message) except Exception, e: - print 'Error while sending %s: %s' % (report_info_path, str(e)) + logging.info('Error while sending %s: %s' % (report_info_path, str(e))) continue emailed_mark_file = open(emailed_mark_path, 'w') emailed_mark_file.close() - print 'Marked %s.' % emailed_mark_path + logging.info('Marked %s.' % emailed_mark_path) def load_configuration(config): global REPORTS_PATH, REPORTER_ADDRESS, LIST_ADDRESS, \ SMTP_USER, SMTP_PASSWORD, SMTP_SERVER, SMTP_PORT + format = "%(asctime)s %(message)s" + log_path = config.get('mailer', 'log_path') + logging.basicConfig(filename=log_path, level=logging.INFO, format=format) + REPORTS_PATH = config.get('feedback', 'reports_path') if not os.path.exists(REPORTS_PATH): - print 'Reports directory (%s) does not exists.' % REPORTS_PATH + logging.error('Reports directory (%s) does not exists.' % REPORTS_PATH) sys.exit(-1) REPORTER_ADDRESS = config.get('mailer', 'reporter_address') diff --git a/sugar-fbserver.spec b/sugar-fbserver.spec index 8af033f..0908da4 100644 --- a/sugar-fbserver.spec +++ b/sugar-fbserver.spec @@ -1,6 +1,6 @@ Name: sugar-fbserver Version: 0.2 -Release: 4 +Release: 5 Vendor: Activity Central Summary: Sugar debugging feedback server Group: Applications/Internet @@ -59,6 +59,9 @@ chkconfig --level 345 fbserverd off %changelog +* Fri Mar 25 2011 Martin Abente. +- Add custom log to mailer. + * Thu Mar 24 2011 Martin Abente. - Improved email body content format - Check mailer section existance. -- cgit v0.9.1