prefect日志标准化

This commit is contained in:
2026-03-26 11:09:37 +08:00
parent bef5c46f85
commit 543491f03c
2 changed files with 25 additions and 1 deletions
+11 -1
View File
@@ -4,7 +4,7 @@ import os
import time
from datetime import datetime
from pathlib import Path
from typing import Dict, Iterable, List, Optional, Tuple
from typing import Callable, Dict, Iterable, List, Optional, Tuple
from urllib import error, parse, request
try:
@@ -98,12 +98,22 @@ FIELD_TYPE_HINTS = {
"商品数量": FIELD_TYPE_NUMBER,
}
LOGGER_WRITER: Optional[Callable[[str, str], None]] = None
def log(message: str, *, level: str = "INFO") -> None:
if LOGGER_WRITER is not None:
LOGGER_WRITER(level, message)
return
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{timestamp}] [{level}] {message}")
def set_logger_writer(writer: Optional[Callable[[str, str], None]]) -> None:
global LOGGER_WRITER
LOGGER_WRITER = writer
def load_env(path: Path) -> None:
if not path.exists():
return