2.5.8 完善 LOG API,改善 log 显示模式

This commit is contained in:
EstrellaXD
2022-07-09 21:51:13 +08:00
parent 3c70343db9
commit 15bb8d7d60
6 changed files with 25 additions and 34 deletions

1
.gitignore vendored
View File

@@ -172,3 +172,4 @@ cython_debug/
/auto_bangumi/parser/analyser/tmdb.py
/auto_bangumi/run_debug.sh
/auto_bangumi/debug_run.sh

View File

@@ -3,7 +3,7 @@ import re
import uvicorn
from uvicorn.config import LOGGING_CONFIG
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.responses import HTMLResponse, FileResponse
from fastapi.templating import Jinja2Templates
from pydantic import BaseModel
import logging
@@ -13,7 +13,6 @@ from conf import settings, parse
from utils import json_config
logger = logging.getLogger(__name__)
app = FastAPI()
@@ -32,9 +31,9 @@ def get_data():
@app.get("/api/v1/log")
def get_log():
with open(settings.log_path, "r") as f:
return f.read()
async def get_log():
log_path = settings.log_path
return FileResponse(log_path)
@app.get("/api/v1/resetRule")
@@ -45,12 +44,8 @@ def reset_rule():
return "Success"
class RuleName(BaseModel):
name: str
@app.post("/api/v1/removeRule")
def remove_rule(name: RuleName):
@app.get("api/v1/removeRule/{name}")
def remove_rule(name: str):
datas = json_config.load(settings.info_path)["bangumi_info"]
for data in datas:
if re.search(name.name.lower(), data["title_raw"].lower()) is not None:
@@ -60,12 +55,8 @@ def remove_rule(name: RuleName):
return "Not matched"
class RSS(BaseModel):
link: str
@app.post("/api/v1/subscriptions")
async def receive(link: RSS):
@app.get("/api/v1/subscribe/{link}")
async def receive(link: str):
client = DownloadClient()
try:
data = RSSAnalyser().rss_to_data(link.link)
@@ -76,17 +67,6 @@ async def receive(link: RSS):
return "Error"
class Search(BaseModel):
group: str
title: str
subtitle: str
@app.post("/api/v1/search")
async def search(input: Search):
return "Nothing Happened"
class AddRule(BaseModel):
title: str
season: int
@@ -107,7 +87,7 @@ def run():
logger.debug("Please copy `const_dev.py` to `const_dev.py` to use custom settings")
else:
settings.init()
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "%(asctime)s %(levelprefix)s %(message)s"
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "[%(asctime)s] %(levelprefix)s\t%(message)s"
uvicorn.run(app, host="0.0.0.0", port=settings.webui_port)

View File

@@ -12,6 +12,13 @@ from core import RSSAnalyser, DownloadClient, Renamer, FullSeasonGet
logger = logging.getLogger(__name__)
def reset_log():
try:
os.remove(settings.log_path)
except FileNotFoundError:
pass
def load_data_file():
info_path = settings.info_path
if not os.path.exists(info_path):
@@ -85,6 +92,7 @@ def run():
else:
settings.init()
# 初始化
reset_log()
setup_logger()
show_info()
download_client = DownloadClient()

View File

@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
DEFAULT_SETTINGS = {
"version": "2.5.7",
"version": "2.5.8",
"data_version": 4.0,
"host_ip": "localhost:8080",
"sleep_time": 7200,

View File

@@ -4,11 +4,13 @@ from conf import settings
def setup_logger():
level = logging.DEBUG if settings.debug_mode else logging.INFO
DATE_FORMAT = "%Y-%m-%d %X"
LOGGING_FORMAT = "%(asctime)s %(levelname)s: %(message)s"
LOGGING_FORMAT = "[%(asctime)s] %(levelname)s:\t%(message)s"
logging.basicConfig(
level=level,
datefmt=DATE_FORMAT,
format=LOGGING_FORMAT,
encoding="utf-8",
handlers=[
logging.FileHandler(settings.log_path),
logging.StreamHandler(),
]
)

View File

@@ -25,7 +25,7 @@ class QbDownloader:
self._client.auth_log_in()
break
except LoginFailed:
logger.warning(
logger.debug(
f"Can't login qBittorrent Server {host} by {username}, retry in {settings.connect_retry_interval}"
)
time.sleep(settings.connect_retry_interval)