Skip to content
Open
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
2 changes: 1 addition & 1 deletion annotated_logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion annotated_logger/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 22 additions & 1 deletion test/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 - {{}}"