From 9d19654cbd99c2133bfb86253c63da33621ea110 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Wed, 14 Sep 2016 22:13:34 +0200 Subject: [PATCH] logging: use the actual root logger as the root logger Use the actual root logger (`logging.getLogger()`) rather than the `ipa` logger (or the `root` logger in case of ipa-ods-exporter) as the root logger. Always configure logging on the root logger. Reviewed-By: Martin Basti --- daemons/dnssec/ipa-dnskeysyncd | 3 +-- daemons/dnssec/ipa-ods-exporter | 14 ++++++-------- ipapython/ipa_log_manager.py | 16 ++++------------ ipaserver/advise/base.py | 2 +- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/daemons/dnssec/ipa-dnskeysyncd b/daemons/dnssec/ipa-dnskeysyncd index 89b2f54d8..e70aa8e15 100755 --- a/daemons/dnssec/ipa-dnskeysyncd +++ b/daemons/dnssec/ipa-dnskeysyncd @@ -25,8 +25,7 @@ api.bootstrap(context='dns', confdir=paths.ETC_IPA, in_server=True) api.finalize() log = root_logger if api.env.debug: - log.setLevel(logging.DEBUG) -#log.addHandler(systemd.journal.JournalHandler()) + root_logger.setLevel(logging.DEBUG) # Global state watcher_running = True diff --git a/daemons/dnssec/ipa-ods-exporter b/daemons/dnssec/ipa-ods-exporter index 6fe11dcc3..bd3082dd4 100755 --- a/daemons/dnssec/ipa-ods-exporter +++ b/daemons/dnssec/ipa-ods-exporter @@ -35,6 +35,7 @@ import ipalib from ipalib.constants import SOFTHSM_DNSSEC_TOKEN_LABEL from ipalib.install.kinit import kinit_keytab from ipapython.dn import DN +from ipapython.ipa_log_manager import root_logger from ipapython import ipaldap from ipaplatform.paths import paths from ipaserver.dnssec.abshsm import sync_pkcs11_metadata, wrappingmech_name2id @@ -601,10 +602,10 @@ def cleanup_ldap_zone(log, ldap, dns_dn, zone_name): log.debug('deleting key metadata "%s"', ldap_key.dn) ldap.delete_entry(ldap_key) -log = logging.getLogger('root') +log = root_logger # this service is usually socket-activated -log.addHandler(systemd.journal.JournalHandler()) -log.setLevel(level=logging.DEBUG) +root_logger.addHandler(systemd.journal.JournalHandler()) +root_logger.setLevel(level=logging.DEBUG) if len(sys.argv) > 2: print(__doc__) @@ -612,13 +613,10 @@ if len(sys.argv) > 2: # program was likely invoked from console, log to it elif len(sys.argv) == 2: console = logging.StreamHandler() - log.addHandler(console) + root_logger.addHandler(console) # IPA framework initialization -ipalib.api.bootstrap( - context='dns', confdir=paths.ETC_IPA, - in_server=True, log=None, # no logging to file -) +ipalib.api.bootstrap(context='dns', confdir=paths.ETC_IPA, in_server=True) ipalib.api.finalize() # Kerberos initialization diff --git a/ipapython/ipa_log_manager.py b/ipapython/ipa_log_manager.py index f8074b108..ae847b1c7 100644 --- a/ipapython/ipa_log_manager.py +++ b/ipapython/ipa_log_manager.py @@ -26,12 +26,9 @@ import six # Module exports __all__ = ['log_mgr', 'root_logger', 'standard_logging_setup', - 'IPA_ROOT_LOGGER_NAME', 'ISO8601_UTC_DATETIME_FMT', + 'ISO8601_UTC_DATETIME_FMT', 'LOGGING_FORMAT_STDERR', 'LOGGING_FORMAT_STDOUT', 'LOGGING_FORMAT_FILE'] -# Our root logger, all loggers will be descendents of this. -IPA_ROOT_LOGGER_NAME = 'ipa' - # Format string for time.strftime() to produce a ISO 8601 date time # formatted string in the UTC time zone. ISO8601_UTC_DATETIME_FMT = '%Y-%m-%dT%H:%M:%SZ' @@ -61,14 +58,9 @@ LOGGING_FORMAT_STANDARD_FILE = '%(asctime)s %(levelname)s %(message)s' def get_logger(who, bind_logger_names=False): if isinstance(who, six.string_types): - obj_name = who + logger_name = who else: - obj_name = '%s.%s' % (who.__module__, who.__class__.__name__) - - if obj_name == IPA_ROOT_LOGGER_NAME: - logger_name = obj_name - else: - logger_name = IPA_ROOT_LOGGER_NAME + '.' + obj_name + logger_name = '%s.%s' % (who.__module__, who.__class__.__name__) logger = logging.getLogger(logger_name) @@ -142,4 +134,4 @@ def standard_logging_setup(filename=None, verbose=False, debug=False, # Single shared instance of log manager log_mgr = sys.modules[__name__] -root_logger = logging.getLogger(IPA_ROOT_LOGGER_NAME) +root_logger = logging.getLogger() diff --git a/ipaserver/advise/base.py b/ipaserver/advise/base.py index b849c80a9..19c34feb5 100644 --- a/ipaserver/advise/base.py +++ b/ipaserver/advise/base.py @@ -507,7 +507,7 @@ class IpaAdvise(admintool.AdminTool): advise_api.finalize() if not self.options.verbose: # Do not print connection information by default - logger_name = r'ipa\.ipalib\.plugins\.rpcclient' + logger_name = r'ipalib\.plugins\.rpcclient' root_logger.addFilter(Filter(logger_name, logging.WARNING)) # With no argument, print the list out and exit