Skip to content

Commit

Permalink
chore: Fix deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Dec 8, 2023
1 parent 2e748a9 commit a3ed8ec
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/gallia/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import atexit
import datetime
import gzip
import io
import logging
Expand All @@ -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
Expand All @@ -32,7 +32,7 @@
from logging import _ExcInfoType


tz = datetime.utcnow().astimezone().tzinfo
tz = datetime.datetime.now(datetime.UTC).tzinfo


@unique
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a3ed8ec

Please sign in to comment.