mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
fix(log): add support for CONFIG_DIR through environment variables
This commit is contained in:
+8
-2
@@ -2,7 +2,7 @@ import inspect
|
|||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any, Optional
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from pydantic import BaseSettings
|
from pydantic import BaseSettings
|
||||||
@@ -14,6 +14,8 @@ class LogSettings(BaseSettings):
|
|||||||
"""
|
"""
|
||||||
日志设置
|
日志设置
|
||||||
"""
|
"""
|
||||||
|
# 配置文件目录
|
||||||
|
CONFIG_DIR: Optional[str] = None
|
||||||
# 是否为调试模式
|
# 是否为调试模式
|
||||||
DEBUG: bool = False
|
DEBUG: bool = False
|
||||||
# 日志级别(DEBUG、INFO、WARNING、ERROR等)
|
# 日志级别(DEBUG、INFO、WARNING、ERROR等)
|
||||||
@@ -27,12 +29,16 @@ class LogSettings(BaseSettings):
|
|||||||
# 文件日志格式
|
# 文件日志格式
|
||||||
LOG_FILE_FORMAT: str = "【%(levelname)s】%(asctime)s - %(message)s"
|
LOG_FILE_FORMAT: str = "【%(levelname)s】%(asctime)s - %(message)s"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def CONFIG_PATH(self):
|
||||||
|
return SystemUtils.get_config_path(self.CONFIG_DIR)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def LOG_PATH(self):
|
def LOG_PATH(self):
|
||||||
"""
|
"""
|
||||||
获取日志存储路径
|
获取日志存储路径
|
||||||
"""
|
"""
|
||||||
return SystemUtils.get_config_path() / "logs"
|
return self.CONFIG_PATH / "logs"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def LOG_MAX_FILE_SIZE_BYTES(self):
|
def LOG_MAX_FILE_SIZE_BYTES(self):
|
||||||
|
|||||||
+6
-2
@@ -5,7 +5,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Union, Tuple
|
from typing import List, Union, Tuple, Optional
|
||||||
|
|
||||||
import docker
|
import docker
|
||||||
import psutil
|
import psutil
|
||||||
@@ -473,10 +473,14 @@ class SystemUtils:
|
|||||||
return os.stat(src).st_dev == os.stat(dest).st_dev
|
return os.stat(src).st_dev == os.stat(dest).st_dev
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_config_path() -> Path:
|
def get_config_path(config_dir: Optional[str] = None) -> Path:
|
||||||
"""
|
"""
|
||||||
获取配置路径
|
获取配置路径
|
||||||
"""
|
"""
|
||||||
|
if not config_dir:
|
||||||
|
config_dir = os.getenv("CONFIG_DIR")
|
||||||
|
if config_dir:
|
||||||
|
return Path(config_dir)
|
||||||
if SystemUtils.is_docker():
|
if SystemUtils.is_docker():
|
||||||
return Path("/config")
|
return Path("/config")
|
||||||
elif SystemUtils.is_frozen():
|
elif SystemUtils.is_frozen():
|
||||||
|
|||||||
Reference in New Issue
Block a user