Skip to content

Commit

Permalink
vdk-structlog: Test for compatibility for log_level_module propagation (
Browse files Browse the repository at this point in the history
#2922)

This change ensures that vdk-structlog tests covers the log_level_module
functionality compabitibility with vdk-structlog log configuration.

Testing done: unit tests

Signed-off-by: Gabriel Georgiev <[email protected]>
  • Loading branch information
gabrielgeorgiev1 authored Nov 29, 2023
1 parent ffeaeac commit 0758787
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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

0 comments on commit 0758787

Please sign in to comment.