diff --git a/flake.lock b/flake.lock index 05ab3d477..3229b00b0 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1696227680, - "narHash": "sha256-G6Lt2qzQGl3NrI3WS4aJ40eMZRxgnhrbblnftBM3aGM=", + "lastModified": 1702037461, + "narHash": "sha256-5G9qC12Fwe4f/zTeP6xAJJ8vJ9H7Vc1nodvMTeu2X/s=", "owner": "nixos", "repo": "nixpkgs", - "rev": "b56f06f3e8c6f48973a43765f4b02c756ba30da4", + "rev": "6a6d3373898c5fbd3ab8626e965f8b80cc932bb4", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index e329d1d3f..55b4e5439 100644 --- a/flake.nix +++ b/flake.nix @@ -14,8 +14,8 @@ devShell.x86_64-linux = pkgs.mkShell { buildInputs = with pkgs; [ poetry - python310 python311 + python312 ]; shellHook = '' LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [stdenv.cc.cc]} diff --git a/src/gallia/log.py b/src/gallia/log.py index 52ea44582..74ea02739 100644 --- a/src/gallia/log.py +++ b/src/gallia/log.py @@ -5,6 +5,7 @@ from __future__ import annotations import atexit +import datetime import gzip import io import logging @@ -17,7 +18,6 @@ import traceback from collections.abc import Iterator from dataclasses import dataclass -from datetime import datetime from enum import Enum, IntEnum, unique from logging.handlers import QueueHandler, QueueListener from pathlib import Path @@ -32,7 +32,7 @@ from logging import _ExcInfoType -tz = datetime.utcnow().astimezone().tzinfo +tz = datetime.datetime.now(datetime.UTC).tzinfo @unique @@ -380,7 +380,7 @@ def _colorize_msg(data: str, levelno: int) -> tuple[str, int]: def _format_record( # noqa: PLR0913 - dt: datetime, + dt: datetime.datetime, name: str, data: str, levelno: int, @@ -427,7 +427,7 @@ class PenlogRecord: module: str host: str data: str - datetime: datetime + datetime: datetime.datetime # FIXME: Enums are slow. priority: PenlogPriority tags: list[str] | None = None @@ -475,12 +475,12 @@ def parse_json(cls, data: bytes) -> Self: match record: case _PenlogRecordV1(): try: - dt = datetime.fromisoformat(record.timestamp) + dt = datetime.datetime.fromisoformat(record.timestamp) except ValueError: # Workaround for broken ISO strings. Go produced broken strings. :) # We have some old logfiles with this shortcoming. datestr, _ = record.timestamp.split(".", 2) - dt = datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%S") + dt = datetime.datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%S") if record.tags is not None: tags = record.tags @@ -505,7 +505,7 @@ def parse_json(cls, data: bytes) -> Self: module=record.module, host=record.host, data=record.data, - datetime=datetime.fromisoformat(record.datetime), + datetime=datetime.datetime.fromisoformat(record.datetime), priority=PenlogPriority(record.priority), tags=record.tags, line=record.line, @@ -726,7 +726,7 @@ def format(self, record: logging.LogRecord) -> str: host=self.hostname, data=record.getMessage(), priority=PenlogPriority.from_level(record.levelno).value, - datetime=datetime.fromtimestamp(record.created, tz=tz).isoformat(), + datetime=datetime.datetime.fromtimestamp(record.created, tz=tz).isoformat(), line=f"{record.pathname}:{record.lineno}", stacktrace=stacktrace, tags=tags, @@ -760,7 +760,7 @@ def format( ) return _format_record( - dt=datetime.fromtimestamp(record.created), + dt=datetime.datetime.fromtimestamp(record.created), name=record.name, data=record.getMessage(), levelno=record.levelno, diff --git a/tests/test_transports.py b/tests/test_transports.py index 891cdac18..eb6278877 100644 --- a/tests/test_transports.py +++ b/tests/test_transports.py @@ -38,9 +38,8 @@ async def listen(self, target: TargetURI) -> None: async def accept(self) -> TCPTransport: return await self.queue.get() - async def close(self) -> None: + def close(self) -> None: self.server.close() - await self.server.wait_closed() async def _echo_test( @@ -66,7 +65,7 @@ async def tcp_server() -> AsyncIterator[TCPServer]: tcp_server = TCPServer() await tcp_server.listen(listen_target) yield tcp_server - await tcp_server.close() + tcp_server.close() @pytest.mark.asyncio @@ -127,7 +126,7 @@ async def test_tcp_linesep_request(tcp_server: TCPServer) -> None: @pytest.mark.asyncio async def test_tcp_timeout(tcp_server: TCPServer) -> None: client = await TCPLinesTransport.connect(TargetURI("tcp-lines://127.0.0.1:1234")) - _ = await tcp_server.accept() + await tcp_server.accept() with pytest.raises(asyncio.TimeoutError): await client.request(b"hello", timeout=0.5)