This commit is contained in:
2026-04-25 17:45:04 +03:30
parent aa24fc22b0
commit ec90642482
4 changed files with 116 additions and 22 deletions
+12
View File
@@ -1,3 +1,15 @@
try:
import pymysql
except ImportError: # pragma: no cover - optional fallback when mysqlclient is unavailable
pymysql = None
else: # pragma: no cover - import side effect
# Django 5's MySQL backend checks the mysqlclient version string during import.
# PyMySQL exposes a legacy compatibility version, so override it before installing
# the MySQLdb shim.
pymysql.version_info = (2, 2, 1, "final", 0)
pymysql.__version__ = "2.2.1"
pymysql.install_as_MySQLdb()
try:
from .celery import app as celery_app
except ImportError: # pragma: no cover - fallback for test environments
+31 -12
View File
@@ -12,7 +12,21 @@ load_dotenv()
BASE_DIR = Path(__file__).resolve().parent.parent
LOG_DIR = Path(os.environ.get("LOG_DIR", BASE_DIR / "logs"))
LOG_DIR.mkdir(parents=True, exist_ok=True)
def _can_use_file_logging(log_dir: Path) -> bool:
try:
log_dir.mkdir(parents=True, exist_ok=True)
probe_file = log_dir / ".write_test"
with probe_file.open("a", encoding="utf-8"):
pass
probe_file.unlink(missing_ok=True)
return True
except OSError:
return False
FILE_LOGGING_ENABLED = _can_use_file_logging(LOG_DIR)
SECRET_KEY = os.environ.get("SECRET_KEY", "django-insecure-dev-only")
DEBUG = os.environ.get("DEBUG", "0") == "1"
@@ -192,29 +206,34 @@ LOGGING = {
"class": "logging.StreamHandler",
"formatter": "standard",
},
"file": {
"class": "logging.handlers.TimedRotatingFileHandler",
"filename": str(LOG_DIR / "app.log"),
"when": "midnight",
"backupCount": 14,
"encoding": "utf-8",
"formatter": "standard",
},
},
"loggers": {
"django": {
"handlers": ["console", "file"],
"handlers": ["console"],
"level": os.environ.get("DJANGO_LOG_LEVEL", "INFO"),
"propagate": False,
},
"rag": {
"handlers": ["console", "file"],
"handlers": ["console"],
"level": os.environ.get("RAG_LOG_LEVEL", "INFO"),
"propagate": False,
},
},
"root": {
"handlers": ["console", "file"],
"handlers": ["console"],
"level": os.environ.get("ROOT_LOG_LEVEL", "INFO"),
},
}
if FILE_LOGGING_ENABLED:
LOGGING["handlers"]["file"] = {
"class": "logging.handlers.TimedRotatingFileHandler",
"filename": str(LOG_DIR / "app.log"),
"when": "midnight",
"backupCount": 14,
"encoding": "utf-8",
"formatter": "standard",
}
LOGGING["loggers"]["django"]["handlers"].append("file")
LOGGING["loggers"]["rag"]["handlers"].append("file")
LOGGING["root"]["handlers"].append("file")