changeset 2204:c574f206f39f

fix recursion EmailHandler problem
author Ana Balica <ana.balica@gmail.com>
date Mon, 23 Sep 2013 20:51:49 +0200
parents 1dbca960f9f6
children 90ef29715d9e
files MoinMoin/log.py
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/log.py	Mon Sep 23 20:50:38 2013 +0200
+++ b/MoinMoin/log.py	Mon Sep 23 20:51:49 2013 +0200
@@ -103,6 +103,7 @@
 
 configured = False
 fallback_config = False
+in_email_handler = False
 
 import warnings
 
@@ -198,15 +199,21 @@
 
         Send the record to the specified addresses
         """
-        from MoinMoin.mail.sendmail import sendmail
-        from flask import current_app as app
-        cfg = app.cfg
         # the app config is accessible after logging is initialized, so set the
         # arguments and make the decision to send mail or not here
-        toaddrs = self.toaddrs if self.toaddrs else cfg.admin_emails
+        from flask import current_app as app
+        if not app.cfg.email_tracebacks:
+            return
+
+        global in_email_handler
+        if in_email_handler:
+            return
+        in_email_handler = True
+        toaddrs = self.toaddrs if self.toaddrs else app.cfg.admin_emails
         log_level = logging.getLevelName(self.level)
         subject = self.subject if self.subject else u'[{0}][{1}] Log message'.format(
-            cfg.sitename, log_level)
+            app.cfg.sitename, log_level)
         msg = self.format(record)
-        if app.cfg.email_tracebacks:
-            sendmail(subject, msg, to=toaddrs)
+        from MoinMoin.mail.sendmail import sendmail
+        sendmail(subject, msg, to=toaddrs)
+        in_email_handler = False