Skip to content

Commit

Permalink
Make sure we have timestamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Oct 2, 2023
1 parent e953374 commit 97c0a23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/service/logging/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from watchtower import CloudWatchLogHandler

from core.service.logging.configuration import LogLevel
from core.util.datetime_helpers import utc_now

if TYPE_CHECKING:
from mypy_boto3_logs import CloudWatchLogsClient
Expand Down Expand Up @@ -54,6 +55,7 @@ def ensure_str(s: Any) -> Any:
level=record.levelname,
filename=record.filename,
message=message,
timestamp=utc_now().isoformat(),
)
if record.exc_info:
data["traceback"] = self.formatException(record.exc_info)
Expand Down
3 changes: 3 additions & 0 deletions tests/core/service/logging/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from unittest.mock import MagicMock

import pytest
from freezegun import freeze_time
from watchtower import CloudWatchLogHandler

from core.service.logging.configuration import LogLevel
Expand All @@ -20,6 +21,7 @@


class TestJSONFormatter:
@freeze_time("1990-05-05")
def test_format(self) -> None:
formatter = JSONFormatter()

Expand All @@ -42,6 +44,7 @@ def test_format(self) -> None:
)
data = json.loads(formatter.format(record))
assert "some logger" == data["name"]
assert "1990-05-05T00:00:00+00:00" == data["timestamp"]
assert "DEBUG" == data["level"]
assert "A message" == data["message"]
assert "pathname" == data["filename"]
Expand Down

0 comments on commit 97c0a23

Please sign in to comment.