summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-31 18:55:32 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-31 18:55:32 -0600
commit5269d1396c2e299d7fc66b55df7a84d482927549 (patch)
treed9432036b387eab2ac81021c520a0fd39c56936f
parenta23d41a57f43c3a0f298d3918ae1712181fa544e (diff)
downloadfreeipa-5269d1396c2e299d7fc66b55df7a84d482927549.tar.gz
freeipa-5269d1396c2e299d7fc66b55df7a84d482927549.tar.xz
freeipa-5269d1396c2e299d7fc66b55df7a84d482927549.zip
Logging formats are now env variables; added log_format_stderr_debug format used when env.debug is True
-rw-r--r--ipalib/constants.py50
-rw-r--r--ipalib/plugable.py20
-rw-r--r--ipalib/util.py1
3 files changed, 43 insertions, 28 deletions
diff --git a/ipalib/constants.py b/ipalib/constants.py
index f4a440c65..7b0e1661e 100644
--- a/ipalib/constants.py
+++ b/ipalib/constants.py
@@ -22,10 +22,38 @@
All constants centralized in one file.
"""
+
# The section to read in the config files, i.e. [global]
CONFIG_SECTION = 'global'
+# Log format for console output
+LOG_FORMAT_STDERR = ': '.join([
+ '%(name)s',
+ '%(levelname)s',
+ '%(message)s',
+])
+
+
+# Log format for console output when env.dubug is True:
+LOG_FORMAT_STDERR_DEBUG = ' '.join([
+ '%(levelname)s',
+ '%(message)r',
+ '%(lineno)d',
+ '%(filename)s',
+])
+
+
+# Tab-delimited log format for file (easy to opened in a spreadsheet):
+LOG_FORMAT_FILE = ' '.join([
+ '%(created)f',
+ '%(levelname)s',
+ '%(message)r', # Using %r for repr() so message is a single line
+ '%(lineno)d',
+ '%(pathname)s',
+])
+
+
# The default configuration for api.env
# This is a tuple instead of a dict so that it is immutable.
# To create a dict with this config, just "d = dict(DEFAULT_CONFIG)".
@@ -55,6 +83,11 @@ DEFAULT_CONFIG = (
('debug', False),
('mode', 'production'),
+ # Logging:
+ ('log_format_stderr', LOG_FORMAT_STDERR),
+ ('log_format_stderr_debug', LOG_FORMAT_STDERR_DEBUG),
+ ('log_format_file', LOG_FORMAT_FILE),
+
# ********************************************************
# The remaining keys are never set from the values here!
# ********************************************************
@@ -87,20 +120,3 @@ DEFAULT_CONFIG = (
('log', None), # Path to log file
)
-
-
-LOGGING_CONSOLE_FORMAT = ': '.join([
- '%(name)s',
- '%(levelname)s',
- '%(message)s',
-])
-
-
-# Tab-delimited format designed to be easily opened in a spreadsheet:
-LOGGING_FILE_FORMAT = ' '.join([
- '%(created)f',
- '%(levelname)s',
- '%(message)r', # Using %r for repr() so message is a single line
- '%(pathname)s',
- '%(lineno)d',
-])
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index f552b61f6..ccaf1f159 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -35,7 +35,7 @@ from os import path
import errors
from errors import check_type, check_isinstance
from config import Environment, Env
-from constants import LOGGING_FILE_FORMAT, LOGGING_CONSOLE_FORMAT, DEFAULT_CONFIG
+from constants import DEFAULT_CONFIG
import util
@@ -785,14 +785,15 @@ class API(DictProxy):
# Add stderr handler:
stderr = logging.StreamHandler()
- stderr.setFormatter(logging.Formatter(LOGGING_CONSOLE_FORMAT))
+ format = self.env.log_format_stderr
if self.env.debug:
- level = logging.DEBUG
+ format = self.env.log_format_stderr_debug
+ stderr.setLevel(logging.DEBUG)
elif self.env.verbose:
- level = logging.INFO
+ stderr.setLevel(logging.INFO)
else:
- level = logging.WARNING
- stderr.setLevel(level)
+ stderr.setLevel(logging.WARNING)
+ stderr.setFormatter(logging.Formatter(format))
log.addHandler(stderr)
# Add file handler:
@@ -806,12 +807,11 @@ class API(DictProxy):
log.warn('Could not create log_dir %r', log_dir)
return
handler = logging.FileHandler(self.env.log)
- handler.setFormatter(logging.Formatter(LOGGING_FILE_FORMAT))
+ handler.setFormatter(logging.Formatter(self.env.log_format_file))
if self.env.debug:
- level = logging.DEBUG
+ handler.setLevel(logging.DEBUG)
else:
- level = logging.INFO
- handler.setLevel(level)
+ handler.setLevel(logging.INFO)
log.addHandler(handler)
def bootstrap_from_options(self, options=None, context=None):
diff --git a/ipalib/util.py b/ipalib/util.py
index 48a3a1296..c16520654 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -26,7 +26,6 @@ from os import path
import imp
import optparse
import krbV
-from constants import LOGGING_CONSOLE_FORMAT, LOGGING_FILE_FORMAT
def xmlrpc_marshal(*args, **kw):