changeset 523:81e35b223dd6

shorten the __init__() method of !CommandLineInterface by extracting the logging configuration into another method
author fschwarz
date Sat, 05 Mar 2011 14:53:03 +0000
parents 918569a5a855
children eef19ada4296
files babel/messages/frontend.py
diffstat 1 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/babel/messages/frontend.py
+++ b/babel/messages/frontend.py
@@ -626,21 +626,7 @@
 
         options, args = self.parser.parse_args(argv[1:])
 
-        # Configure logging
-        self.log = logging.getLogger('babel')
-        self.log.setLevel(options.loglevel)
-        # Don't add a new handler for every instance initialization (#227), this
-        # would cause duplicated output when the CommandLineInterface as an
-        # normal Python class.
-        if self.log.handlers:
-            handler = self.log.handlers[0]
-        else:
-            handler = logging.StreamHandler()
-            self.log.addHandler(handler)
-        handler.setLevel(options.loglevel)
-        formatter = logging.Formatter('%(message)s')
-        handler.setFormatter(formatter)
-
+        self._configure_logging(options.loglevel)
         if options.list_locales:
             identifiers = localedata.list()
             longest = max([len(identifier) for identifier in identifiers])
@@ -664,6 +650,21 @@
 
         return getattr(self, cmdname)(args[1:])
 
+    def _configure_logging(self, loglevel):
+        self.log = logging.getLogger('babel')
+        self.log.setLevel(loglevel)
+        # Don't add a new handler for every instance initialization (#227), this
+        # would cause duplicated output when the CommandLineInterface as an
+        # normal Python class.
+        if self.log.handlers:
+            handler = self.log.handlers[0]
+        else:
+            handler = logging.StreamHandler()
+            self.log.addHandler(handler)
+        handler.setLevel(loglevel)
+        formatter = logging.Formatter('%(message)s')
+        handler.setFormatter(formatter)
+
     def _help(self):
         print self.parser.format_help()
         print "commands:"
Copyright (C) 2012-2017 Edgewall Software