-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.py
More file actions
25 lines (19 loc) · 689 Bytes
/
Copy pathlog.py
File metadata and controls
25 lines (19 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import logging
from config import LOG_FILE, LOG_LINES, LEVEL
logger = logging.getLogger(__name__)
# Hàm xử lí.
def get_last_logs(lines: int = LOG_LINES) -> str:
try:
if not LOG_FILE.exists():
return "Chưa có file log."
with LOG_FILE.open("r", encoding="utf-8", errors="ignore") as f:
data = f.readlines()
return "".join(data[-lines:]) or "Log hiện tại đang trống."
except Exception as e:
logger.exception("Lỗi khi đọc log")
return f"Đã có lỗi khi đọc log: {e}"
logging.basicConfig(
filename=str(LOG_FILE),
level=LEVEL,
format="%(asctime)s | %(levelname)s | %(message)s",
)