refactor logging setup: improve log file path handling for development and frozen application

This commit is contained in:
Ross
2025-11-24 11:48:13 +00:00
parent eb061992a3
commit 21328b53dd
+14 -1
View File
@@ -71,7 +71,20 @@ DELETE_FILES_ON_UPLOAD = True
DEBUG = False
logging.getLogger('niceGUI').setLevel(logging.INFO)
logger.add("uploader.log", rotation="10 MB")
# Choose a log file path that works both during development and when the
# application is frozen into a single executable (PyInstaller --onefile).
try:
if getattr(sys, "frozen", False):
# When frozen, place logs next to the executable
base_path = Path(sys.executable).resolve().parent
else:
base_path = Path(__file__).resolve().parent
except Exception:
base_path = Path.cwd()
log_path = base_path / "uploader.log"
logger.add(str(log_path), rotation="10 MB")
if DEBUG:
BASE_SITE_URL = "http://localhost:8000"