mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-22 23:23:30 -06:00
Remove deprecated object logger
The object logger methods been deprecated for about two years since release 4.6.0. The log manager used to moneky-patch additional log methods like info(), warning(), and error() into API plugin objects. The methods have been replaced by calls to module logger objects in 4.6.0. Remove monkey-patch logger methods, log manager, and its root logger from ipapython.ipa_log_manager. Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Thomas Woerner <twoerner@redhat.com>
This commit is contained in:
parent
5ecede781b
commit
36c65c4aaa
@ -46,7 +46,6 @@ from ipalib.base import ReadOnly, lock, islocked
|
|||||||
from ipalib.constants import DEFAULT_CONFIG
|
from ipalib.constants import DEFAULT_CONFIG
|
||||||
from ipapython import ipa_log_manager, ipautil
|
from ipapython import ipa_log_manager, ipautil
|
||||||
from ipapython.ipa_log_manager import (
|
from ipapython.ipa_log_manager import (
|
||||||
log_mgr,
|
|
||||||
LOGGING_FORMAT_FILE,
|
LOGGING_FORMAT_FILE,
|
||||||
LOGGING_FORMAT_STDERR)
|
LOGGING_FORMAT_STDERR)
|
||||||
from ipapython.version import VERSION, API_VERSION, DEFAULT_PLUGINS
|
from ipapython.version import VERSION, API_VERSION, DEFAULT_PLUGINS
|
||||||
@ -144,7 +143,6 @@ class Plugin(ReadOnly):
|
|||||||
self.__finalize_called = False
|
self.__finalize_called = False
|
||||||
self.__finalized = False
|
self.__finalized = False
|
||||||
self.__finalize_lock = threading.RLock()
|
self.__finalize_lock = threading.RLock()
|
||||||
log_mgr.get_logger(self, True)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __name_getter(cls):
|
def __name_getter(cls):
|
||||||
@ -438,7 +436,6 @@ class API(ReadOnly):
|
|||||||
Initialize environment variables and logging.
|
Initialize environment variables and logging.
|
||||||
"""
|
"""
|
||||||
self.__doing('bootstrap')
|
self.__doing('bootstrap')
|
||||||
self.log = log_mgr.get_logger(self)
|
|
||||||
self.env._bootstrap(**overrides)
|
self.env._bootstrap(**overrides)
|
||||||
self.env._finalize_core(**dict(DEFAULT_CONFIG))
|
self.env._finalize_core(**dict(DEFAULT_CONFIG))
|
||||||
|
|
||||||
|
@ -20,11 +20,9 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import warnings
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Module exports
|
# Module exports
|
||||||
__all__ = ['log_mgr', 'root_logger', 'standard_logging_setup',
|
__all__ = ['standard_logging_setup',
|
||||||
'ISO8601_UTC_DATETIME_FMT',
|
'ISO8601_UTC_DATETIME_FMT',
|
||||||
'LOGGING_FORMAT_STDERR', 'LOGGING_FORMAT_STDOUT', 'LOGGING_FORMAT_FILE']
|
'LOGGING_FORMAT_STDERR', 'LOGGING_FORMAT_STDOUT', 'LOGGING_FORMAT_FILE']
|
||||||
|
|
||||||
@ -55,82 +53,6 @@ LOGGING_FORMAT_STANDARD_CONSOLE = '%(name)-12s: %(levelname)-8s %(message)s'
|
|||||||
LOGGING_FORMAT_STANDARD_FILE = '%(asctime)s %(levelname)s %(message)s'
|
LOGGING_FORMAT_STANDARD_FILE = '%(asctime)s %(levelname)s %(message)s'
|
||||||
|
|
||||||
|
|
||||||
class _DeprecatedLogger:
|
|
||||||
def __init__(self, logger, name):
|
|
||||||
self._logger = logger
|
|
||||||
self._name = name
|
|
||||||
|
|
||||||
def _warn(self):
|
|
||||||
warnings.warn(
|
|
||||||
"{} is deprecated, use a module-level logger".format(self._name),
|
|
||||||
DeprecationWarning)
|
|
||||||
|
|
||||||
def debug(self, *args, **kwargs):
|
|
||||||
self._warn()
|
|
||||||
self._logger.debug(*args, **kwargs)
|
|
||||||
|
|
||||||
def info(self, *args, **kwargs):
|
|
||||||
self._warn()
|
|
||||||
self._logger.info(*args, **kwargs)
|
|
||||||
|
|
||||||
def warning(self, *args, **kwargs):
|
|
||||||
self._warn()
|
|
||||||
self._logger.warning(*args, **kwargs)
|
|
||||||
|
|
||||||
def error(self, *args, **kwargs):
|
|
||||||
self._warn()
|
|
||||||
self._logger.error(*args, **kwargs)
|
|
||||||
|
|
||||||
def critical(self, *args, **kwargs):
|
|
||||||
self._warn()
|
|
||||||
self._logger.critical(*args, **kwargs)
|
|
||||||
|
|
||||||
def exception(self, *args, **kwargs):
|
|
||||||
self._warn()
|
|
||||||
self._logger.exception(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def get_logger(who, bind_logger_names=False):
|
|
||||||
if isinstance(who, str):
|
|
||||||
warnings.warn(
|
|
||||||
"{}.log_mgr.get_logger is deprecated, use "
|
|
||||||
"logging.getLogger".format(__name__),
|
|
||||||
DeprecationWarning)
|
|
||||||
|
|
||||||
logger_name = who
|
|
||||||
else:
|
|
||||||
caller_globals = sys._getframe(1).f_globals
|
|
||||||
logger_name = caller_globals.get('__name__', '__main__')
|
|
||||||
if logger_name == '__main__':
|
|
||||||
logger_name = caller_globals.get('__file__', logger_name)
|
|
||||||
logger_name = os.path.basename(logger_name)
|
|
||||||
|
|
||||||
logger = logging.getLogger(logger_name)
|
|
||||||
|
|
||||||
if not isinstance(who, str):
|
|
||||||
obj_name = '%s.%s' % (who.__module__, who.__class__.__name__)
|
|
||||||
logger = _DeprecatedLogger(logger, obj_name)
|
|
||||||
|
|
||||||
if bind_logger_names:
|
|
||||||
method = 'log'
|
|
||||||
if hasattr(who, method):
|
|
||||||
raise ValueError('%s is already bound to %s' % (method, repr(who)))
|
|
||||||
setattr(who, method, logger)
|
|
||||||
|
|
||||||
for method in ('debug',
|
|
||||||
'info',
|
|
||||||
'warning',
|
|
||||||
'error',
|
|
||||||
'exception',
|
|
||||||
'critical'):
|
|
||||||
if hasattr(who, method):
|
|
||||||
raise ValueError(
|
|
||||||
'%s is already bound to %s' % (method, repr(who)))
|
|
||||||
setattr(who, method, getattr(logger, method))
|
|
||||||
|
|
||||||
return logger
|
|
||||||
|
|
||||||
|
|
||||||
class Filter:
|
class Filter:
|
||||||
def __init__(self, regexp, level):
|
def __init__(self, regexp, level):
|
||||||
self.regexp = re.compile(regexp)
|
self.regexp = re.compile(regexp)
|
||||||
@ -195,10 +117,3 @@ def convert_log_level(value):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError('unknown log level (%s)' % value)
|
raise ValueError('unknown log level (%s)' % value)
|
||||||
return level
|
return level
|
||||||
|
|
||||||
|
|
||||||
# Single shared instance of log manager
|
|
||||||
log_mgr = sys.modules[__name__]
|
|
||||||
|
|
||||||
root_logger = _DeprecatedLogger(logging.getLogger(),
|
|
||||||
'{}.log_mgr.root_logger'.format(__name__))
|
|
||||||
|
@ -77,14 +77,6 @@ class test_Plugin(ClassChecker):
|
|||||||
assert o.summary == u'<%s.%s>' % (another_subclass.__module__,
|
assert o.summary == u'<%s.%s>' % (another_subclass.__module__,
|
||||||
another_subclass.__name__)
|
another_subclass.__name__)
|
||||||
|
|
||||||
# Test that Plugin makes sure the subclass hasn't defined attributes
|
|
||||||
# whose names conflict with the logger methods set in Plugin.__init__():
|
|
||||||
class check(self.cls):
|
|
||||||
info = 'whatever'
|
|
||||||
e = raises(Exception, check, api)
|
|
||||||
assert str(e) == \
|
|
||||||
"info is already bound to ipatests.test_ipalib.test_plugable.check()"
|
|
||||||
|
|
||||||
def test_finalize(self):
|
def test_finalize(self):
|
||||||
"""
|
"""
|
||||||
Test the `ipalib.plugable.Plugin.finalize` method.
|
Test the `ipalib.plugable.Plugin.finalize` method.
|
||||||
|
Loading…
Reference in New Issue
Block a user