Found & fixed minor issue with doc on default_level property, please use this version of the patch instead.

--
John Dennis <jden...@redhat.com>

Looking to carve out IT costs?
www.redhat.com/carveoutcosts/
>From 4203a6aa6e9768d576daf80fc686e7e96aa397f3 Mon Sep 17 00:00:00 2001
From: John Dennis <jden...@redhat.com>
Date: Wed, 30 Nov 2011 11:08:42 -0500
Subject: [PATCH 55/55-1] Restore default log level in server to INFO
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

The default log level for server messages captured by httpd's
error_log historically was INFO. The log_manager patch had it set to
ERROR, this patch resets it back to INFO.

Although it would have been trival to set the default_level to INFO in
IPALogManager.configure_from_env() that is not logically the correct
place. It would be much better if the default_level can be reset by
simply assigning it to the log_mgr. To accomplish that
LogManager.default_level was converted to a property with a getter and
setter. The setter runs LogManager.apply_configuratin() after the
default_level is modified. LogManager.set_default_level() was also
added to allow simultaneously updating the configure_state.

While testing some minor problems were observed and also fixed:

* Removed some print statement which had been left in by mistake

* Removed the ability to set the handler level in the config file
  because of chicken-and-egg issues of when handlers get created.
  The Env config file format is too inflexible to support detailed
  logging configuration. If the Env config format is ever made more
  flexible we can come back and add this back in. The handler config
  setting in Env had never been used and never worked so there is no
  issue in removing it.
---
 ipalib/plugable.py           |    1 +
 ipapython/ipa_log_manager.py |   47 ------------------------------------------
 ipapython/log_manager.py     |   43 ++++++++++++++++++++++++++++++++++---
 3 files changed, 40 insertions(+), 51 deletions(-)

diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 2da361e..e0b6e7f 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -469,6 +469,7 @@ class API(DictProxy):
         if log_mgr.configure_state != 'default' or self.env.validate_api:
             return
 
+        log_mgr.default_level = 'info'
         log_mgr.configure_from_env(self.env, configure_state='api')
         # Add stderr handler:
         level = 'info'
diff --git a/ipapython/ipa_log_manager.py b/ipapython/ipa_log_manager.py
index 11e30d1..7841eab 100644
--- a/ipapython/ipa_log_manager.py
+++ b/ipapython/ipa_log_manager.py
@@ -75,7 +75,6 @@ class IPALogManager(LogManager):
     '''
 
     log_logger_level_config_re = re.compile(r'^log_logger_level_(debug|info|warn|warning|error|critical|\d+)$')
-    log_handler_level_config_re = re.compile(r'^log_handler_(\S+)_level$')
 
     def __init__(self, configure_state=None):
         '''
@@ -117,37 +116,11 @@ class IPALogManager(LogManager):
           will usually need to escape the dot in the logger names by
           preceeding it with a backslash.
 
-        Handler Levels
-          *log_handler_XXX_level = level*
-
-          Handler levels may be specified with a key containing the
-          name of the handler (XXX) and whose value is the level. For
-          example::
-
-            log_handler_console_level = debug
-
-          Would set the console handler level to debug.
-
-          These are the predefined log handlers:
-
-          console
-            Writes to stderr.
-          file
-            Writes to the default log file.
-
-
         The return value of this function is a dict with the following
         format:
 
         logger_regexps
           List of (regexp, level) tuples
-        handlers
-          Dict, key is handler name, value is dict of handler config.
-
-          Handler config dict:
-
-          level
-            handler log level
 
         :parameters:
           env
@@ -158,9 +131,7 @@ class IPALogManager(LogManager):
             use configure_state to track the state of the log manager.
         '''
         logger_regexps = []
-        handlers = {}
         config = {'logger_regexps' : logger_regexps,
-                  'handlers'       : handlers,
                  }
 
         for attr in ('debug', 'verbose'):
@@ -178,27 +149,9 @@ class IPALogManager(LogManager):
                 regexps = re.split('\s*,\s*', value)
                 # Add the regexp, it maps to the configured level
                 for regexp in regexps:
-                    print "%s %s" % (regexp, level)
                     logger_regexps.append((regexp, level))
                 continue
 
-            # Get handler configuration
-            match = IPALogManager.log_handler_level_config_re.search(attr)
-            if match:
-                value = getattr(env, attr)
-                try:
-                    level = parse_log_level(value)
-                except Exception, e:
-                    print >>sys.stderr, 'ERROR could not parse log handler level: %s=%s' % (attr, value)
-                    continue
-                name = match.group(1)
-                print "%s %s" % (name, level)
-                handler_config = handlers.get(name)
-                if handler_config is None:
-                    handler_config = {'name' : name}
-                handler_config['level'] = level
-                continue
-
         self.configure(config, configure_state)
         return config
 
diff --git a/ipapython/log_manager.py b/ipapython/log_manager.py
index 736d953..c847142 100644
--- a/ipapython/log_manager.py
+++ b/ipapython/log_manager.py
@@ -769,21 +769,56 @@ class LogManager(object):
           LogManager instance
 
         '''
+        self.loggers = {}       # dict, key is logger name, value is logger object
+        self.handlers = {}      # dict, key is handler name, value is handler object
+
         self.configure_state = configure_state
         self.root_logger_name = root_logger_name
-        self.default_level = logging.ERROR
+        self.default_level = 'error'
         self.debug = False
         self.verbose = False
         self.logger_regexps = []
 
-        self.loggers = {}       # dict, key is logger name, value is logger object
-        self.handlers = {}      # dict, key is handler name, value is handler object
-
         self.root_logger = self.get_logger(self.root_logger_name)
         # Stop loggers and handlers from searching above our root
         self.root_logger.propagate = False
 
 
+    def _get_default_level(self):
+        return self._default_level
+
+    def _set_default_level(self, value):
+        level = parse_log_level(value)
+        self._default_level = level
+        self.apply_configuration()
+
+    default_level = property(_get_default_level, _set_default_level,
+                             doc='see log_manager.parse_log_level()` for details on how the level can be specified during assignement.')
+
+    def set_default_level(self, level, configure_state=None):
+        '''
+        Reset the default logger level, updates all loggers.
+        Note, the default_level may also be set by assigning to the
+        default_level attribute but that does not update the configure_state,
+        this method is provided as a convenience to simultaneously set the
+        configure_state if so desired.
+        
+        :parameters:
+          level
+            The new default level for the log manager.  See
+            `log_manager.parse_log_level()` for details on how the
+            level can be specified.
+          configure_state
+            If other than None update the log manger's configure_state
+            variable to this object. Clients of the log manager can
+            use configure_state to track the state of the log manager.
+
+        '''
+        level = parse_log_level(level)
+        self._default_level = level
+        self.apply_configuration(configure_state)
+
+
     def __str__(self):
         '''
         When str() is called on the LogManager output it's state.
-- 
1.7.7.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to