新增日志存储逻辑

Co-Authored-By: ouzhuowei <190020754@qq.com>
This commit is contained in:
ouzhuowei
2026-02-06 12:33:35 +08:00
parent 80e9c866a0
commit 30cf16af0c
3 changed files with 92 additions and 2 deletions

View File

@@ -84,6 +84,16 @@ class InitDbOptionEnum(str, Enum):
POSTGRES = "postgres"
class LogLevelEnum(str, Enum):
"""Log level enumeration"""
DEBUG = "DEBUG"
INFO = "INFO"
WARNING = "WARNING"
ERROR = "ERROR"
CRITICAL = "CRITICAL"
def _to_bool(value: bool | str) -> bool:
if isinstance(value, bool):
return value
@@ -299,6 +309,31 @@ async def parse_cmd(argv: Optional[Sequence[str]] = None):
rich_help_panel="Proxy Configuration",
),
] = config.IP_PROXY_PROVIDER_NAME,
log_save_enable: Annotated[
str,
typer.Option(
"--log_save_enable",
help="Whether to save logs to file, supports yes/true/t/y/1 or no/false/f/n/0",
rich_help_panel="Log Configuration",
show_default=True,
),
] = str(config.LOG_SAVE_ENABLE),
log_save_path: Annotated[
str,
typer.Option(
"--log_save_path",
help="Log file save path, default is ./logs",
rich_help_panel="Log Configuration",
),
] = config.LOG_SAVE_PATH,
log_save_level: Annotated[
LogLevelEnum,
typer.Option(
"--log_save_level",
help="Log save level (DEBUG | INFO | WARNING | ERROR | CRITICAL)",
rich_help_panel="Log Configuration",
),
] = _coerce_enum(LogLevelEnum, config.LOG_SAVE_LEVEL, LogLevelEnum.INFO),
) -> SimpleNamespace:
"""MediaCrawler 命令行入口"""
@@ -306,6 +341,7 @@ async def parse_cmd(argv: Optional[Sequence[str]] = None):
enable_sub_comment = _to_bool(get_sub_comment)
enable_headless = _to_bool(headless)
enable_ip_proxy_value = _to_bool(enable_ip_proxy)
enable_log_save = _to_bool(log_save_enable)
init_db_value = init_db.value if init_db else None
# Parse specified_id and creator_id into lists
@@ -330,6 +366,9 @@ async def parse_cmd(argv: Optional[Sequence[str]] = None):
config.ENABLE_IP_PROXY = enable_ip_proxy_value
config.IP_PROXY_POOL_COUNT = ip_proxy_pool_count
config.IP_PROXY_PROVIDER_NAME = ip_proxy_provider_name
config.LOG_SAVE_ENABLE = enable_log_save
config.LOG_SAVE_PATH = log_save_path
config.LOG_SAVE_LEVEL = log_save_level.value
# Set platform-specific ID lists for detail/creator mode
if specified_id_list: