Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file logging level issue #289

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion broker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ def fork_broker():
if pid:
logger.info(f"Running broker in the background with pid: {pid}")
sys.exit(0)
update_log_level(None, None, "silent")
b_log.set_log_level("silent")
b_log.set_file_logging("silent")


def handle_keyboardinterrupt(*args):
Expand Down
16 changes: 9 additions & 7 deletions broker/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ def redact_dynaconf(self, data):


def patch_awx_for_verbosity(api):
"""Patch the awxkit API to log when we're at trace level."""
client = api.client
awx_log = client.log

"""Patch the awxkit API to enable trace-level logging of API calls to Ansible provider."""
awx_log = api.client.log
awx_log.parent = logzero.logger

def patch(cls, name):
Expand Down Expand Up @@ -116,7 +114,12 @@ def set_file_logging(level=settings.logging.file_level, path="logs/broker.log"):
silent = True
log_level = LOG_LEVEL.INFO
else:
log_level = resolve_log_level(level)
# Allow override of file logging level with --log-level, if the new level is lower than
# settings.logging.file_level. Otherwise, use the value from settings.
old_log_level = resolve_log_level(settings.logging.file_level)
new_log_level = resolve_log_level(level)
log_level = new_log_level if new_log_level < old_log_level else old_log_level

path = BROKER_DIRECTORY.joinpath(path)
path.parent.mkdir(parents=True, exist_ok=True)
logzero.logfile(
Expand All @@ -138,8 +141,7 @@ def setup_logzero(
):
"""Call logzero setup with the given settings."""
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
if isinstance(level, str) and level.lower() == "trace":
patch_awx_for_verbosity(awxkit.api)
patch_awx_for_verbosity(awxkit.api)
set_log_level(level)
set_file_logging(file_level, path)
if formatter:
Expand Down