Add timestamp to logs (#3245)
This commit is contained in:
parent
7f88e909c6
commit
e46aa7c1b0
|
|
@ -4,6 +4,7 @@ import sys
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import asdict, is_dataclass
|
from dataclasses import asdict, is_dataclass
|
||||||
|
from datetime import UTC, datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -264,6 +265,11 @@ def info(
|
||||||
log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
|
log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
|
||||||
|
|
||||||
|
|
||||||
|
def _timestamp() -> str:
|
||||||
|
now = datetime.now(tz=UTC)
|
||||||
|
return now.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
|
||||||
def debug(
|
def debug(
|
||||||
*msgs: str,
|
*msgs: str,
|
||||||
level: int = logging.DEBUG,
|
level: int = logging.DEBUG,
|
||||||
|
|
@ -319,7 +325,10 @@ def log(
|
||||||
log_file: Path = storage['LOG_PATH'] / storage['LOG_FILE']
|
log_file: Path = storage['LOG_PATH'] / storage['LOG_FILE']
|
||||||
|
|
||||||
with log_file.open('a') as fp:
|
with log_file.open('a') as fp:
|
||||||
fp.write(f"{orig_string}\n")
|
ts = _timestamp()
|
||||||
|
level_name = logging.getLevelName(level)
|
||||||
|
out = f"[{ts}] - {level_name} - {orig_string}\n"
|
||||||
|
fp.write(out)
|
||||||
|
|
||||||
Journald.log(text, level=level)
|
Journald.log(text, level=level)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue