From 46815c016ff2a26e6d0628385e3604acaab61c16 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:21:23 +1300 Subject: [PATCH 1/9] Implement destination aware log level filtering - Add optional destination_label to start_logging function. - Add dictionary to map destination label to minimum log level. - The default log handler gets the destination level for the label provided in start_logging; falling back to the default value if no label was given, or if the given label has not been assigned a level. --- src/yosys_mau/task_loop/logging.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/yosys_mau/task_loop/logging.py b/src/yosys_mau/task_loop/logging.py index fbbb6ee..6ad35a1 100644 --- a/src/yosys_mau/task_loop/logging.py +++ b/src/yosys_mau/task_loop/logging.py @@ -17,7 +17,10 @@ current_task_or_none, root_task, ) -from .context import task_context +from .context import ( + TaskContextDict, + task_context, +) Level = Literal["debug", "info", "warning", "error"] @@ -118,17 +121,17 @@ class LogContext: When set, the downgrading happens before the `LogEvent` is emitted. """ - level: Level = "info" - """The minimum log level to display/log. + dest_levels: TaskContextDict[str, Level] = TaskContextDict() + """The minimum log level to display/log for named destinations. This does not stop `LogEvent` of smaller levels to be emitted. It is only used to filter which messages to actually print/log. Hence, it does not affect any user installed `LogEvent` handlers. - - When logging to multiple destinations, currently there is no way to specify this per - destination. """ + level: Level = "info" + """The minimum log level used if a destination has no specific level.""" + log_format: Callable[[LogEvent], str] = default_formatter """The formatter used to format log messages. @@ -297,7 +300,10 @@ def log_exception(exception: BaseException, raise_error: bool = True) -> LoggedE def start_logging( - file: IO[Any] | None = None, err: bool = False, color: bool | None = None + file: IO[Any] | None = None, + err: bool = False, + color: bool | None = None, + destination_label: str | None = None, ) -> None: """Start logging all log events reaching the current task. @@ -310,6 +316,8 @@ def start_logging( :param color: Whether to use colors. Defaults to ``True`` for terminals and ``False`` otherwise. When the ``NO_COLOR`` environment variable is set, this will be ignored and no colors will be used. + :param destination_label: Used to look up destination specific log level filtering. Used with + `LogContext.dest_levels`. """ if _no_color: color = False @@ -318,7 +326,12 @@ def log_handler(event: LogEvent): if file and file.closed: remove_log_handler() return - source_level = _level_order[event.source[LogContext].level] + logContext = event.source[LogContext] + if destination_label: + destination_level = logContext.dest_levels.get(destination_label, logContext.level) + else: + destination_level = logContext.level + source_level = _level_order[destination_level] event_level = _level_order[event.level] if event_level < source_level: return From 5afdda4e809ecb514cf1961d38b917fa75808254 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:22:05 +1300 Subject: [PATCH 2/9] Add tests for destination log level filtering --- tests/task_loop/test_logging.py | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/task_loop/test_logging.py b/tests/task_loop/test_logging.py index 5e7186e..ca53b99 100644 --- a/tests/task_loop/test_logging.py +++ b/tests/task_loop/test_logging.py @@ -140,6 +140,77 @@ def main(): ] +def test_log_destinations(): + log_output1 = io.StringIO() + log_output2 = io.StringIO() + + def main(): + tl.LogContext.time_format = fixed_time + tl.logging.start_logging(file=log_output1, destination_label="1") + tl.logging.start_logging(file=log_output2, destination_label="2") + + tl.LogContext.dest_levels["2"] = "debug" + tl.log_debug("line 1") + tl.log("line 2") + + del tl.LogContext.dest_levels["2"] + tl.LogContext.level = "debug" + tl.LogContext.dest_levels["1"] = "info" + tl.log_debug("line 3") + tl.log("line 4") + + tl.run_task_loop(main) + + assert log_output1.getvalue().splitlines() == [ + "12:34:56 line 2", + "12:34:56 line 4", + ] + + assert log_output2.getvalue().splitlines() == [ + "12:34:56 DEBUG: line 1", + "12:34:56 line 2", + "12:34:56 DEBUG: line 3", + "12:34:56 line 4", + ] + + +def test_log_no_label(): + log_output1 = io.StringIO() + log_output2 = io.StringIO() + + def main(): + tl.LogContext.time_format = fixed_time + tl.logging.start_logging(file=log_output1) + tl.logging.start_logging(file=log_output2, destination_label="2") + + # tl.LogContext.level = "info" # implied + tl.LogContext.dest_levels["2"] = "debug" + tl.log_debug("line 1") + tl.log("line 2") + + tl.LogContext.level = "debug" + tl.LogContext.dest_levels["1"] = "info" + tl.LogContext.dest_levels["2"] = "warning" + tl.log_debug("line 3") + + tl.LogContext.dest_levels[None] = "warning" + tl.LogContext.dest_levels[""] = "warning" + tl.log("line 4") + + tl.run_task_loop(main) + + assert log_output1.getvalue().splitlines() == [ + "12:34:56 line 2", + "12:34:56 DEBUG: line 3", + "12:34:56 line 4", + ] + + assert log_output2.getvalue().splitlines() == [ + "12:34:56 DEBUG: line 1", + "12:34:56 line 2", + ] + + def test_exception_logging(): log_output = io.StringIO() From 5b54dd8ebaf9ab4fded900b131711ef765dd3efa Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:06:26 +1300 Subject: [PATCH 3/9] Paremetrize log destination tests --- tests/task_loop/test_logging.py | 80 ++++++++++++--------------------- 1 file changed, 28 insertions(+), 52 deletions(-) diff --git a/tests/task_loop/test_logging.py b/tests/task_loop/test_logging.py index ca53b99..91f2750 100644 --- a/tests/task_loop/test_logging.py +++ b/tests/task_loop/test_logging.py @@ -140,75 +140,51 @@ def main(): ] -def test_log_destinations(): - log_output1 = io.StringIO() - log_output2 = io.StringIO() - - def main(): - tl.LogContext.time_format = fixed_time - tl.logging.start_logging(file=log_output1, destination_label="1") - tl.logging.start_logging(file=log_output2, destination_label="2") - - tl.LogContext.dest_levels["2"] = "debug" - tl.log_debug("line 1") - tl.log("line 2") - - del tl.LogContext.dest_levels["2"] - tl.LogContext.level = "debug" - tl.LogContext.dest_levels["1"] = "info" - tl.log_debug("line 3") - tl.log("line 4") - - tl.run_task_loop(main) - - assert log_output1.getvalue().splitlines() == [ - "12:34:56 line 2", - "12:34:56 line 4", - ] - - assert log_output2.getvalue().splitlines() == [ - "12:34:56 DEBUG: line 1", - "12:34:56 line 2", - "12:34:56 DEBUG: line 3", - "12:34:56 line 4", - ] - - -def test_log_no_label(): - log_output1 = io.StringIO() - log_output2 = io.StringIO() +@pytest.mark.parametrize( + "label,expected", + [ + ("default", [2, 3, 4, 6]), + ("debug", [1, 2, 3, 4, 5, 6]), + ("info", [2, 4, 5, 6]), + ("warning", [5, 6]), + ("error", [6]), + ("varied", [1, 2, 4, 6]), + ], +) +def test_log_destinations(label: str, expected: list[str]): + log_output = io.StringIO() def main(): tl.LogContext.time_format = fixed_time - tl.logging.start_logging(file=log_output1) - tl.logging.start_logging(file=log_output2, destination_label="2") + tl.logging.start_logging(file=log_output, destination_label=label) # tl.LogContext.level = "info" # implied - tl.LogContext.dest_levels["2"] = "debug" + tl.LogContext.dest_levels["info"] = "info" + tl.LogContext.dest_levels["debug"] = "debug" + tl.LogContext.dest_levels["warning"] = "warning" + tl.LogContext.dest_levels["error"] = "error" + + tl.LogContext.dest_levels["varied"] = "debug" tl.log_debug("line 1") tl.log("line 2") tl.LogContext.level = "debug" - tl.LogContext.dest_levels["1"] = "info" - tl.LogContext.dest_levels["2"] = "warning" + tl.LogContext.dest_levels["varied"] = "warning" tl.log_debug("line 3") + del tl.LogContext.dest_levels["varied"] tl.LogContext.dest_levels[None] = "warning" tl.LogContext.dest_levels[""] = "warning" tl.log("line 4") - tl.run_task_loop(main) + tl.LogContext.level = "error" + tl.log_warning("line 5") + tl.log_error("line 6", raise_error=False) - assert log_output1.getvalue().splitlines() == [ - "12:34:56 line 2", - "12:34:56 DEBUG: line 3", - "12:34:56 line 4", - ] + tl.run_task_loop(main) - assert log_output2.getvalue().splitlines() == [ - "12:34:56 DEBUG: line 1", - "12:34:56 line 2", - ] + trimmed_output = [int(x[-1]) for x in log_output.getvalue().splitlines()] + assert trimmed_output == expected def test_exception_logging(): From 850244715e09fbcbd1d93f01cf3f07ad5e65c6b3 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:38:58 +1300 Subject: [PATCH 4/9] logging: Testing nested logging --- tests/task_loop/test_logging.py | 115 ++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/tests/task_loop/test_logging.py b/tests/task_loop/test_logging.py index 91f2750..08f0465 100644 --- a/tests/task_loop/test_logging.py +++ b/tests/task_loop/test_logging.py @@ -187,6 +187,121 @@ def main(): assert trimmed_output == expected +@pytest.mark.parametrize("task", ["root", "task1", "task2"]) +@pytest.mark.parametrize("label", ["debug", "info", "warning", "mixed1", "mixed2"]) +def test_nested_destinations(task: str, label: str): + log_output = io.StringIO() + + async def main(): + tl.LogContext.time_format = fixed_time + tl.LogContext.scope = "?root?" + if task == "root": + tl.logging.start_logging(file=log_output, destination_label=label) + tl.LogContext.dest_levels["mixed1"] = "warning" + + tl.LogContext.dest_levels["debug"] = "debug" + tl.LogContext.dest_levels["info"] = "info" + tl.LogContext.dest_levels["warning"] = "warning" + tl.LogContext.dest_levels["error"] = "error" + tl.LogContext.dest_levels["source"] = "warning" + + tl.log("line 0") + sync_event = asyncio.Event() + + async def run_task1(): + tl.LogContext.scope = "?root?task1?" + if task == "task1": + tl.logging.start_logging(file=log_output, destination_label=label) + tl.LogContext.dest_levels["mixed1"] = "info" + + tl.LogContext.dest_levels["mixed2"] = { + "root": "debug", + "task1": "info", + "task2": "", + }[task] + + task2 = tl.Task(on_run=run_task2) + tl.log("line 2") + + await task2.started + + tl.log_debug("line 4") + + sync_event.set() + + await task2.finished + + tl.log("line 6") + + async def run_task2(): + tl.LogContext.scope = "?root?task1?task2?" + if task == "task2": + tl.logging.start_logging(file=log_output, destination_label=label) + tl.LogContext.dest_levels["mixed1"] = "debug" + + tl.LogContext.dest_levels["mixed2"] = { + "root": "error", + "task1": "debug", + "task2": "error", + }[task] + + tl.log_debug("line 3") + + await sync_event.wait() + tl.log_warning("line 5") + + task1 = tl.Task(on_run=run_task1) + + tl.log("line 1") + + await task1.finished + + tl.log("line 7") + + tl.run_task_loop(main) + + reference_list = [ + "12:34:56 ?root?: line 0", + "12:34:56 ?root?: line 1", + "12:34:56 ?root?task1?: line 2", + "12:34:56 ?root?task1?task2?: DEBUG: line 3", + "12:34:56 ?root?task1?: DEBUG: line 4", + "12:34:56 ?root?task1?task2?: WARNING: line 5", + "12:34:56 ?root?task1?: line 6", + "12:34:56 ?root?: line 7", + ] + + label_map: dict[str, list[int]] = { + "debug": [0, 1, 2, 3, 4, 5, 6, 7], + "info": [0, 1, 2, 5, 6, 7], + "warning": [5], + } + + if label in label_map: + filtered_list = [x for i, x in enumerate(reference_list) if i in label_map[label]] + expected = [x for x in filtered_list if task in x.split("?")] + else: + # potentially unintuitive, but destination levels come from the emitter not the logger + if label == "mixed1": + task_map: dict[str, list[int]] = { + "root": [5], + "task1": [2, 5, 6], + "task2": [3, 5], + } + elif label == "mixed2": + task_map: dict[str, list[int]] = { + "root": [0, 1, 2, 4, 6, 7], + "task1": [2, 3, 5, 6], + "task2": [], + } + else: + assert False, f"unknown label {label}" + expected = [x for i, x in enumerate(reference_list) if i in task_map[task]] + + print(log_output.getvalue()) + assert log_output.getvalue().splitlines() == expected + + def test_exception_logging(): log_output = io.StringIO() From 4314d77d2dc081decf5808631f2ec09ca785e17c Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:50:43 +1300 Subject: [PATCH 5/9] logging: Fix linting --- tests/task_loop/test_logging.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/task_loop/test_logging.py b/tests/task_loop/test_logging.py index 08f0465..43c0a23 100644 --- a/tests/task_loop/test_logging.py +++ b/tests/task_loop/test_logging.py @@ -173,7 +173,7 @@ def main(): tl.log_debug("line 3") del tl.LogContext.dest_levels["varied"] - tl.LogContext.dest_levels[None] = "warning" + tl.LogContext.dest_levels[None] = "warning" # type:ignore tl.LogContext.dest_levels[""] = "warning" tl.log("line 4") @@ -214,11 +214,7 @@ async def run_task1(): tl.logging.start_logging(file=log_output, destination_label=label) tl.LogContext.dest_levels["mixed1"] = "info" - tl.LogContext.dest_levels["mixed2"] = { - "root": "debug", - "task1": "info", - "task2": "", - }[task] + tl.LogContext.dest_levels["mixed2"] = "debug" if task == "root" else "info" task2 = tl.Task(on_run=run_task2) tl.log("line 2") @@ -239,11 +235,7 @@ async def run_task2(): tl.logging.start_logging(file=log_output, destination_label=label) tl.LogContext.dest_levels["mixed1"] = "debug" - tl.LogContext.dest_levels["mixed2"] = { - "root": "error", - "task1": "debug", - "task2": "error", - }[task] + tl.LogContext.dest_levels["mixed2"] = "debug" if task == "task1" else "error" tl.log_debug("line 3") From 799604e5db2e3fdf2ae4c2e2eaf30a09675b00a7 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:01:35 +1300 Subject: [PATCH 6/9] logging: Use log writing task context for dest_levels Update tests and docs to match. --- src/yosys_mau/task_loop/logging.py | 26 ++++++++++++++++---------- tests/task_loop/test_logging.py | 5 ++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/yosys_mau/task_loop/logging.py b/src/yosys_mau/task_loop/logging.py index 6ad35a1..8c75145 100644 --- a/src/yosys_mau/task_loop/logging.py +++ b/src/yosys_mau/task_loop/logging.py @@ -121,16 +121,14 @@ class LogContext: When set, the downgrading happens before the `LogEvent` is emitted. """ - dest_levels: TaskContextDict[str, Level] = TaskContextDict() - """The minimum log level to display/log for named destinations. + level: Level = "info" + """The minimum log level to display/log. + + Can be overridden for named destinations with dest_levels`. This does not stop `LogEvent` of smaller levels to be emitted. It is only used to filter which messages to actually print/log. Hence, it does not affect any user installed `LogEvent` - handlers. - """ - - level: Level = "info" - """The minimum log level used if a destination has no specific level.""" + handlers.""" log_format: Callable[[LogEvent], str] = default_formatter """The formatter used to format log messages. @@ -148,6 +146,14 @@ class LogContext: Like `log_format` this is looked up by the log writing task, not the emitting task. """ + dest_levels: TaskContextDict[str, Level] = TaskContextDict() + """The minimum log level to display/log for named destinations. + + Like `log_format` this is looked up by the log writing task, not the emitting task. If the + current destination has no key:value pair in this dictionary, the `level` will be looked up by + the task which emit the log. + """ + def log(*args: Any, level: Level = "info", cls: type[LogEvent] = LogEvent) -> LogEvent: """Produce log output. @@ -326,11 +332,11 @@ def log_handler(event: LogEvent): if file and file.closed: remove_log_handler() return - logContext = event.source[LogContext] + emitter_default = event.source[LogContext].level if destination_label: - destination_level = logContext.dest_levels.get(destination_label, logContext.level) + destination_level = LogContext.dest_levels.get(destination_label, emitter_default) else: - destination_level = logContext.level + destination_level = emitter_default source_level = _level_order[destination_level] event_level = _level_order[event.level] if event_level < source_level: diff --git a/tests/task_loop/test_logging.py b/tests/task_loop/test_logging.py index 43c0a23..2615258 100644 --- a/tests/task_loop/test_logging.py +++ b/tests/task_loop/test_logging.py @@ -273,7 +273,6 @@ async def run_task2(): filtered_list = [x for i, x in enumerate(reference_list) if i in label_map[label]] expected = [x for x in filtered_list if task in x.split("?")] else: - # potentially unintuitive, but destination levels come from the emitter not the logger if label == "mixed1": task_map: dict[str, list[int]] = { "root": [5], @@ -282,8 +281,8 @@ async def run_task2(): } elif label == "mixed2": task_map: dict[str, list[int]] = { - "root": [0, 1, 2, 4, 6, 7], - "task1": [2, 3, 5, 6], + "root": [0, 1, 2, 5, 6, 7], + "task1": [2, 5, 6], "task2": [], } else: From 18a176170d4d637f90e05a667fce7f455dc97266 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Tue, 26 Mar 2024 17:23:50 +1300 Subject: [PATCH 7/9] logging: Minor doc fixes --- src/yosys_mau/task_loop/logging.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/yosys_mau/task_loop/logging.py b/src/yosys_mau/task_loop/logging.py index 8c75145..fb766a9 100644 --- a/src/yosys_mau/task_loop/logging.py +++ b/src/yosys_mau/task_loop/logging.py @@ -124,7 +124,7 @@ class LogContext: level: Level = "info" """The minimum log level to display/log. - Can be overridden for named destinations with dest_levels`. + Can be overridden for named destinations with `dest_levels`. This does not stop `LogEvent` of smaller levels to be emitted. It is only used to filter which messages to actually print/log. Hence, it does not affect any user installed `LogEvent` @@ -322,8 +322,8 @@ def start_logging( :param color: Whether to use colors. Defaults to ``True`` for terminals and ``False`` otherwise. When the ``NO_COLOR`` environment variable is set, this will be ignored and no colors will be used. - :param destination_label: Used to look up destination specific log level filtering. Used with - `LogContext.dest_levels`. + :param destination_label: Used to look up destination specific log level filtering. + Used with `LogContext.dest_levels`. """ if _no_color: color = False From 4bed760227654f238f14ec47f77ddc1707d97769 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:01:19 +1200 Subject: [PATCH 8/9] Replace dest_ with destination_ --- src/yosys_mau/task_loop/logging.py | 10 ++++---- tests/task_loop/test_logging.py | 38 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/yosys_mau/task_loop/logging.py b/src/yosys_mau/task_loop/logging.py index fb766a9..1877e3e 100644 --- a/src/yosys_mau/task_loop/logging.py +++ b/src/yosys_mau/task_loop/logging.py @@ -124,7 +124,7 @@ class LogContext: level: Level = "info" """The minimum log level to display/log. - Can be overridden for named destinations with `dest_levels`. + Can be overridden for named destinations with `destination_levels`. This does not stop `LogEvent` of smaller levels to be emitted. It is only used to filter which messages to actually print/log. Hence, it does not affect any user installed `LogEvent` @@ -146,7 +146,7 @@ class LogContext: Like `log_format` this is looked up by the log writing task, not the emitting task. """ - dest_levels: TaskContextDict[str, Level] = TaskContextDict() + destination_levels: TaskContextDict[str, Level] = TaskContextDict() """The minimum log level to display/log for named destinations. Like `log_format` this is looked up by the log writing task, not the emitting task. If the @@ -323,7 +323,7 @@ def start_logging( When the ``NO_COLOR`` environment variable is set, this will be ignored and no colors will be used. :param destination_label: Used to look up destination specific log level filtering. - Used with `LogContext.dest_levels`. + Used with `LogContext.destination_levels`. """ if _no_color: color = False @@ -334,7 +334,9 @@ def log_handler(event: LogEvent): return emitter_default = event.source[LogContext].level if destination_label: - destination_level = LogContext.dest_levels.get(destination_label, emitter_default) + destination_level = LogContext.destination_levels.get( + destination_label, emitter_default + ) else: destination_level = emitter_default source_level = _level_order[destination_level] diff --git a/tests/task_loop/test_logging.py b/tests/task_loop/test_logging.py index 2615258..4976303 100644 --- a/tests/task_loop/test_logging.py +++ b/tests/task_loop/test_logging.py @@ -159,22 +159,22 @@ def main(): tl.logging.start_logging(file=log_output, destination_label=label) # tl.LogContext.level = "info" # implied - tl.LogContext.dest_levels["info"] = "info" - tl.LogContext.dest_levels["debug"] = "debug" - tl.LogContext.dest_levels["warning"] = "warning" - tl.LogContext.dest_levels["error"] = "error" + tl.LogContext.destination_levels["info"] = "info" + tl.LogContext.destination_levels["debug"] = "debug" + tl.LogContext.destination_levels["warning"] = "warning" + tl.LogContext.destination_levels["error"] = "error" - tl.LogContext.dest_levels["varied"] = "debug" + tl.LogContext.destination_levels["varied"] = "debug" tl.log_debug("line 1") tl.log("line 2") tl.LogContext.level = "debug" - tl.LogContext.dest_levels["varied"] = "warning" + tl.LogContext.destination_levels["varied"] = "warning" tl.log_debug("line 3") - del tl.LogContext.dest_levels["varied"] - tl.LogContext.dest_levels[None] = "warning" # type:ignore - tl.LogContext.dest_levels[""] = "warning" + del tl.LogContext.destination_levels["varied"] + tl.LogContext.destination_levels[None] = "warning" # type:ignore + tl.LogContext.destination_levels[""] = "warning" tl.log("line 4") tl.LogContext.level = "error" @@ -197,13 +197,13 @@ async def main(): tl.LogContext.scope = "?root?" if task == "root": tl.logging.start_logging(file=log_output, destination_label=label) - tl.LogContext.dest_levels["mixed1"] = "warning" + tl.LogContext.destination_levels["mixed1"] = "warning" - tl.LogContext.dest_levels["debug"] = "debug" - tl.LogContext.dest_levels["info"] = "info" - tl.LogContext.dest_levels["warning"] = "warning" - tl.LogContext.dest_levels["error"] = "error" - tl.LogContext.dest_levels["source"] = "warning" + tl.LogContext.destination_levels["debug"] = "debug" + tl.LogContext.destination_levels["info"] = "info" + tl.LogContext.destination_levels["warning"] = "warning" + tl.LogContext.destination_levels["error"] = "error" + tl.LogContext.destination_levels["source"] = "warning" tl.log("line 0") sync_event = asyncio.Event() @@ -212,9 +212,9 @@ async def run_task1(): tl.LogContext.scope = "?root?task1?" if task == "task1": tl.logging.start_logging(file=log_output, destination_label=label) - tl.LogContext.dest_levels["mixed1"] = "info" + tl.LogContext.destination_levels["mixed1"] = "info" - tl.LogContext.dest_levels["mixed2"] = "debug" if task == "root" else "info" + tl.LogContext.destination_levels["mixed2"] = "debug" if task == "root" else "info" task2 = tl.Task(on_run=run_task2) tl.log("line 2") @@ -233,9 +233,9 @@ async def run_task2(): tl.LogContext.scope = "?root?task1?task2?" if task == "task2": tl.logging.start_logging(file=log_output, destination_label=label) - tl.LogContext.dest_levels["mixed1"] = "debug" + tl.LogContext.destination_levels["mixed1"] = "debug" - tl.LogContext.dest_levels["mixed2"] = "debug" if task == "task1" else "error" + tl.LogContext.destination_levels["mixed2"] = "debug" if task == "task1" else "error" tl.log_debug("line 3") From 4368c24824ef2b32591251142b024cdd2204f424 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:05:07 +1200 Subject: [PATCH 9/9] Remove destination_levels test assigning to None --- tests/task_loop/test_logging.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/task_loop/test_logging.py b/tests/task_loop/test_logging.py index 4976303..2ee19f6 100644 --- a/tests/task_loop/test_logging.py +++ b/tests/task_loop/test_logging.py @@ -173,7 +173,6 @@ def main(): tl.log_debug("line 3") del tl.LogContext.destination_levels["varied"] - tl.LogContext.destination_levels[None] = "warning" # type:ignore tl.LogContext.destination_levels[""] = "warning" tl.log("line 4")