From 464516489ff029a39446138b16e858e96d157841 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Jul 14 2017 13:55:59 +0000 Subject: logging: do not configure any handlers by default Do not configure stderr handler by default and let the application do the configuration. Fix ipa-dnskeysync-replica and ipa-dnskeysyncd not to add stderr handler twice. Reviewed-By: Martin Basti --- diff --git a/daemons/dnssec/ipa-dnskeysync-replica b/daemons/dnssec/ipa-dnskeysync-replica index c7b9cf3..3745d10 100755 --- a/daemons/dnssec/ipa-dnskeysync-replica +++ b/daemons/dnssec/ipa-dnskeysync-replica @@ -10,7 +10,7 @@ This program should be run only on replicas, not on DNSSEC masters. from binascii import hexlify from gssapi.exceptions import GSSError -import logging + import os import sys @@ -123,14 +123,10 @@ def ldap2replica_zone_keys_sync(log, ldapkeydb, localhsm): # IPA framework initialization -ipalib.api.bootstrap( - context='dns', confdir=paths.ETC_IPA, - in_server=True, log=None, # no logging to file -) +standard_logging_setup(verbose=True, debug=True) +ipalib.api.bootstrap(context='dns', confdir=paths.ETC_IPA, in_server=True) ipalib.api.finalize() -standard_logging_setup(verbose=True, debug = True) # debug=ipalib.api.env.debug) log = root_logger -log.setLevel(level=logging.DEBUG) # Kerberos initialization PRINCIPAL = str('%s/%s' % (DAEMONNAME, ipalib.api.env.host)) diff --git a/daemons/dnssec/ipa-dnskeysyncd b/daemons/dnssec/ipa-dnskeysyncd index fc1a0f6..89b2f54 100755 --- a/daemons/dnssec/ipa-dnskeysyncd +++ b/daemons/dnssec/ipa-dnskeysyncd @@ -3,6 +3,7 @@ # Copyright (C) 2014 FreeIPA Contributors see COPYING for license # +import logging import sys import ldap import ldapurl @@ -19,13 +20,12 @@ from ipaplatform.paths import paths from ipaserver.dnssec.keysyncer import KeySyncer # IPA framework initialization -api.bootstrap( - context='dns', confdir=paths.ETC_IPA, - in_server=True, log=None, # no logging to file -) +standard_logging_setup(verbose=True) +api.bootstrap(context='dns', confdir=paths.ETC_IPA, in_server=True) api.finalize() -standard_logging_setup(verbose=True, debug=api.env.debug) log = root_logger +if api.env.debug: + log.setLevel(logging.DEBUG) #log.addHandler(systemd.journal.JournalHandler()) # Global state diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 1a9164f..012d268 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -457,8 +457,6 @@ class API(ReadOnly): else: level = 'warning' - if 'console' in log_mgr.handlers: - log_mgr.remove_handler('console') log_mgr.create_log_handlers([dict(name='console', stream=sys.stderr, level=level, diff --git a/ipapython/admintool.py b/ipapython/admintool.py index 78bbcec..4c71cb3 100644 --- a/ipapython/admintool.py +++ b/ipapython/admintool.py @@ -230,6 +230,9 @@ class AdminTool(object): Logging to file is only set up after option validation and prompting; before that, all output will go to the console only. """ + if 'console' in ipa_log_manager.log_mgr.handlers: + ipa_log_manager.log_mgr.remove_handler('console') + self._setup_logging(log_file_mode=log_file_mode) def _setup_logging(self, log_file_mode='w', no_file=False): diff --git a/ipapython/ipa_log_manager.py b/ipapython/ipa_log_manager.py index 39c1768..de231ee 100644 --- a/ipapython/ipa_log_manager.py +++ b/ipapython/ipa_log_manager.py @@ -188,8 +188,6 @@ def standard_logging_setup(filename=None, verbose=False, debug=False, format=LOGGING_FORMAT_STANDARD_FILE) handlers.append(file_handler) - if 'console' in log_mgr.handlers: - log_mgr.remove_handler('console') level = 'error' if verbose: level = 'info' @@ -214,14 +212,9 @@ def standard_logging_setup(filename=None, verbose=False, debug=False, #------------------------------------------------------------------------------- # Single shared instance of log manager -# -# By default always starts with stderr console handler at error level -# so messages generated before logging is fully configured have some -# place to got and won't get lost. log_mgr = IPALogManager() log_mgr.configure(dict(default_level='error', - handlers=[dict(name='console', - stream=sys.stderr)]), + handlers=[]), configure_state='default') root_logger = log_mgr.root_logger