diff --git a/annotated_logger/__init__.py b/annotated_logger/__init__.py index be63003..7e64339 100644 --- a/annotated_logger/__init__.py +++ b/annotated_logger/__init__.py @@ -33,7 +33,7 @@ # https://test.pypi.org/project/annotated-logger/ # The dev versions in testpypi can then be pulled in to whatever project needed # the new feature. -VERSION = "1.3.5" # pragma: no mutate +VERSION = "1.3.6" # pragma: no mutate T = TypeVar("T") P = ParamSpec("P") diff --git a/annotated_logger/plugins.py b/annotated_logger/plugins.py index a73ad54..c9f3233 100644 --- a/annotated_logger/plugins.py +++ b/annotated_logger/plugins.py @@ -168,7 +168,9 @@ def filter(self, record: logging.LogRecord) -> bool: name = record.levelname.lower() if name == "info": # pragma: no cover name = "notice" - record.github_annotation = f"{name}::" + elif name == "critical": + name = "error" + record.github_annotation = f"::{name}::" return True diff --git a/test/test_plugins.py b/test/test_plugins.py index 1f144e8..63560dc 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -4,7 +4,7 @@ from requests.exceptions import HTTPError from annotated_logger import AnnotatedAdapter, AnnotatedLogger -from annotated_logger.plugins import BasePlugin, RenamerPlugin +from annotated_logger.plugins import BasePlugin, GitHubActionsPlugin, RenamerPlugin from example.actions import ActionsExample from example.api import ApiClient from example.calculator import Calculator @@ -257,3 +257,24 @@ def test_logs_actions_annotations(self, annotated_logger_mock): in annotated_logger_mock.messages[0] ) annotated_logger_mock.assert_logged("DEBUG", count=0) + + +@pytest.mark.parametrize( + ("level", "command"), + [ + (logging.DEBUG, "debug"), + (logging.INFO, "notice"), + (logging.WARNING, "warning"), + (logging.ERROR, "error"), + (logging.CRITICAL, "error"), + ], +) +def test_actions_workflow_command_format(level, command): + plugin = GitHubActionsPlugin(logging.DEBUG) + record = logging.LogRecord("actions", level, "", 0, "Build failed", (), None) + assert plugin.filter(record) + formatter = logging.Formatter( + "{github_annotation} {message} - {added_attributes}", + style="{", + ) + assert formatter.format(record) == f"::{command}:: Build failed - {{}}"