changeset 499:cbe893a707e4

Prevent multiple handlers being attached to the same logger. Issue: #227 Submitted by: dfraser
author jruigrok
date Tue, 22 Feb 2011 14:30:22 +0000
parents c024900ae605
children c3fb31644920
files ChangeLog babel/messages/frontend.py
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,7 @@
  * Removed ValueError raising for string formatting message checkers if the
    string does not contain any string formattings (ticket #150).
  * Fix Serbian plural forms (ticket #213).
+ * Prevent multiple handlers being added to the same logger (ticket #227).
 
 
 Version 0.9.6
--- a/babel/messages/frontend.py
+++ b/babel/messages/frontend.py
@@ -629,11 +629,14 @@
         # Configure logging
         self.log = logging.getLogger('babel')
         self.log.setLevel(options.loglevel)
-        handler = logging.StreamHandler()
-        handler.setLevel(options.loglevel)
+        if self.log.handlers:
+            handler = self.log.handlers[0]
+        else:
+            handler = logging.StreamHandler()
+            self.log.addHandler(handler)
         formatter = logging.Formatter('%(message)s')
         handler.setFormatter(formatter)
-        self.log.addHandler(handler)
+        handler.setLevel(options.loglevel)
 
         if options.list_locales:
             identifiers = localedata.list()
Copyright (C) 2012-2017 Edgewall Software