summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJohn Dennis <jdennis@redhat.com>2011-11-15 14:39:31 -0500
committerMartin Kosek <mkosek@redhat.com>2011-11-23 09:36:18 +0100
commit56401c1abe7d4c78650acfcd9bbe8c8edc1dac57 (patch)
treea759f9fb51d4e2e110c55dbecc45f436386ee30f /ipalib
parent730f1228a91ec9c6e575181807da2ab994a38071 (diff)
downloadfreeipa-56401c1abe7d4c78650acfcd9bbe8c8edc1dac57.tar.gz
freeipa-56401c1abe7d4c78650acfcd9bbe8c8edc1dac57.tar.xz
freeipa-56401c1abe7d4c78650acfcd9bbe8c8edc1dac57.zip
ticket 2022 - modify codebase to utilize IPALogManager, obsoletes logging
change default_logger_level to debug in configure_standard_logging add new ipa_log_manager module, move log_mgr there, also export root_logger from log_mgr. change all log_manager imports to ipa_log_manager and change log_manager.root_logger to root_logger. add missing import for parse_log_level()
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/constants.py17
-rw-r--r--ipalib/plugable.py66
-rw-r--r--ipalib/plugins/aci.py4
-rw-r--r--ipalib/plugins/cert.py1
-rw-r--r--ipalib/plugins/migration.py1
-rw-r--r--ipalib/util.py8
6 files changed, 31 insertions, 66 deletions
diff --git a/ipalib/constants.py b/ipalib/constants.py
index 7ec897b58..ba5f470b0 100644
--- a/ipalib/constants.py
+++ b/ipalib/constants.py
@@ -59,23 +59,6 @@ CLI_TAB = ' ' # Two spaces
# The section to read in the config files, i.e. [global]
CONFIG_SECTION = 'global'
-# Log format for stderr:
-FORMAT_STDERR = ': '.join([
- 'ipa',
- '%(levelname)s',
- '%(message)s',
-])
-
-# Log format for log file:
-FORMAT_FILE = '\t'.join([
- '%(created)f',
- '%(process)d',
- '%(threadName)s',
- '%(levelname)s',
- '%(message)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)".
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index a76f884d5..d8b07c1e8 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -29,7 +29,6 @@ import re
import sys
import inspect
import threading
-import logging
import os
from os import path
import subprocess
@@ -40,7 +39,8 @@ import util
import text
from text import _
from base import ReadOnly, NameSpace, lock, islocked, check_name
-from constants import DEFAULT_CONFIG, FORMAT_STDERR, FORMAT_FILE
+from constants import DEFAULT_CONFIG
+from ipapython.ipa_log_manager import *
# FIXME: Updated constants.TYPE_ERROR to use this clearer format from wehjit:
TYPE_ERROR = '%s: need a %r; got a %r: %r'
@@ -193,14 +193,7 @@ class Plugin(ReadOnly):
self.summary = '<%s>' % self.fullname
else:
self.summary = unicode(self.doc).split('\n\n', 1)[0].strip()
- log = logging.getLogger(self.fullname)
- for name in ('debug', 'info', 'warning', 'error', 'critical', 'exception'):
- if hasattr(self, name):
- raise StandardError(
- '%s.%s attribute (%r) conflicts with Plugin logger' % (
- self.name, name, getattr(self, name))
- )
- setattr(self, name, getattr(log, name))
+ log_mgr.get_logger(self, True)
if self.label is None:
self.label = text.FixMe(self.name + '.label')
if not isinstance(self.label, text.LazyText):
@@ -307,8 +300,7 @@ class Plugin(ReadOnly):
for name in api:
assert not hasattr(self, name)
setattr(self, name, api[name])
- # FIXME: the 'log' attribute is depreciated. See Plugin.__init__()
- for name in ('env', 'context', 'log'):
+ for name in ('env', 'context'):
if hasattr(api, name):
assert not hasattr(self, name)
setattr(self, name, getattr(api, name))
@@ -469,34 +461,32 @@ class API(DictProxy):
self.__doing('bootstrap')
self.env._bootstrap(**overrides)
self.env._finalize_core(**dict(DEFAULT_CONFIG))
- log = logging.getLogger()
+ object.__setattr__(self, 'log_mgr', log_mgr)
+ log = log_mgr.root_logger
object.__setattr__(self, 'log', log)
-
# If logging has already been configured somewhere else (like in the
# installer), don't add handlers or change levels:
- if len(log.handlers) > 0 or self.env.validate_api:
+ if log_mgr.configure_state != 'default' or self.env.validate_api:
return
- if self.env.debug:
- log.setLevel(logging.DEBUG)
- else:
- log.setLevel(logging.INFO)
-
+ log_mgr.configure_from_env(self.env, configure_state='api')
# Add stderr handler:
- stderr = logging.StreamHandler()
+ level = 'info'
if self.env.debug:
- stderr.setLevel(logging.DEBUG)
+ level = 'debug'
else:
if self.env.context == 'cli':
if self.env.verbose > 0:
- stderr.setLevel(logging.INFO)
+ level = 'info'
else:
- stderr.setLevel(logging.WARNING)
- else:
- stderr.setLevel(logging.INFO)
- stderr.setFormatter(util.LogFormatter(FORMAT_STDERR))
- log.addHandler(stderr)
-
+ level = 'warning'
+
+ if log_mgr.handlers.has_key('console'):
+ log_mgr.remove_handler('console')
+ log_mgr.create_log_handlers([dict(name='console',
+ stream=sys.stderr,
+ level=level,
+ format=LOGGING_FORMAT_STDERR)])
# Add file handler:
if self.env.mode in ('dummy', 'unit_test'):
return # But not if in unit-test mode
@@ -509,17 +499,19 @@ class API(DictProxy):
except OSError:
log.error('Could not create log_dir %r', log_dir)
return
+
+
+ level = 'info'
+ if self.env.debug:
+ level = 'debug'
try:
- handler = logging.FileHandler(self.env.log)
+ log_mgr.create_log_handlers([dict(name='file',
+ filename=self.env.log,
+ level=level,
+ format=LOGGING_FORMAT_FILE)])
except IOError, e:
- log.error('Cannot open log file %r: %s', self.env.log, e.strerror)
+ log.error('Cannot open log file %r: %s', self.env.log, e)
return
- handler.setFormatter(util.LogFormatter(FORMAT_FILE))
- if self.env.debug:
- handler.setLevel(logging.DEBUG)
- else:
- handler.setLevel(logging.INFO)
- log.addHandler(handler)
def build_global_parser(self, parser=None, context=None):
"""
diff --git a/ipalib/plugins/aci.py b/ipalib/plugins/aci.py
index 585dab837..04f25f289 100644
--- a/ipalib/plugins/aci.py
+++ b/ipalib/plugins/aci.py
@@ -126,7 +126,7 @@ from ipalib import output
from ipalib import _, ngettext
if api.env.in_server and api.env.context in ['lite', 'server']:
from ldap import explode_dn
-import logging
+from ipapython.ipa_log_manager import *
ACI_NAME_PREFIX_SEP = ":"
@@ -368,7 +368,7 @@ def _convert_strings_to_acis(acistrs):
try:
acis.append(ACI(a))
except SyntaxError, e:
- logging.warn("Failed to parse: %s" % a)
+ root_logger.warning("Failed to parse: %s" % a)
return acis
def _find_aci_by_name(acis, aciprefix, aciname):
diff --git a/ipalib/plugins/cert.py b/ipalib/plugins/cert.py
index aa3cf2197..130ebc79f 100644
--- a/ipalib/plugins/cert.py
+++ b/ipalib/plugins/cert.py
@@ -32,7 +32,6 @@ from ipalib import util
from ipalib.plugins.virtual import *
from ipalib.plugins.service import split_principal
import base64
-import logging
import traceback
from ipalib.text import _
from ipalib.request import context
diff --git a/ipalib/plugins/migration.py b/ipalib/plugins/migration.py
index 852cc9d64..5d6631f58 100644
--- a/ipalib/plugins/migration.py
+++ b/ipalib/plugins/migration.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import logging
import re
import ldap as _ldap
diff --git a/ipalib/util.py b/ipalib/util.py
index 7a4d256d7..b0574f949 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -23,7 +23,6 @@ Various utility functions.
import os
import imp
-import logging
import time
import socket
import re
@@ -116,13 +115,6 @@ def import_plugins_subpackage(name):
__import__(full_name)
-class LogFormatter(logging.Formatter):
- """
- Log formatter that uses UTC for all timestamps.
- """
- converter = time.gmtime
-
-
def make_repr(name, *args, **kw):
"""
Construct a standard representation of a class instance.