summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/plugable.py1
-rw-r--r--ipapython/ipa_log_manager.py47
-rw-r--r--ipapython/log_manager.py43
3 files changed, 40 insertions, 51 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 2da361e56..e0b6e7f96 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 11e30d11a..7841eabfb 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 736d95310..c84714210 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.