prefect日志标准化
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user