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

vdk-structlog: Test for compatibility for log_level_module propagation #2922

Merged
merged 9 commits into from
Nov 29, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ def run(job_input: IJobInput):
bound_logger.info(
"Log statement with bound context and extra context", extra=extra_fields
)

logging.getLogger("test_structlog").info(f"This log statement should not appear")
18 changes: 12 additions & 6 deletions projects/vdk-plugins/vdk-structlog/tests/test_structlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_structlog(log_format):
{
"VDK_LOGGING_METADATA": f"timestamp,level,file_name,line_number,vdk_job_name,{BOUND_TEST_KEY},{EXTRA_TEST_KEY}",
"VDK_LOGGING_FORMAT": log_format,
"LOG_LEVEL_MODULE": "test_structlog=WARNING",
},
):
logs = _run_job_and_get_logs()
Expand All @@ -77,6 +78,12 @@ def test_structlog(log_format):
logs, "Log statement with bound context and extra context"
)

# due to the log_level_module config specified in the config.ini of the test job
# the 'This log statement should not appear' log should not appear in the output logs
assert (
_get_log_containing_s(logs, "This log statement should not appear") is None
)

_assert_cases(
log_with_no_bound_context,
log_with_bound_context,
Expand Down Expand Up @@ -140,12 +147,11 @@ def _get_log_containing_s(logs, s):
:param s:
:return:
"""
try:
necessary_log = [x for x in logs if s in x][0]
except IndexError as e:
raise Exception("Log cannot be found inside provided job logs") from e

return necessary_log
necessary_log = [x for x in logs if s in x]
if len(necessary_log) == 0:
return None
else:
return necessary_log[0]


def _assert_cases(
Expand Down
Loading