Skip to content

The only downloader you need. 下载器的集大成者。

refactor(log): 将日志配置从主程序迁移至应用初始化模块

XiaoYouChR1ecda914b52c
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.py
index ff1ec382..5fb57449 100644
--- a/Ghost-Downloader-3.py
+++ b/Ghost-Downloader-3.py
@@ -22,11 +22,9 @@ application = SingletonApplication(sys.argv, "gd3")
# --- Start Program ---
from loguru import logger
-import time
import warnings
from PySide6.QtCore import QTranslator
-from app.supports.config import VERSION
from app.view.windows.main_window import MainWindow
from app.supports.recorder import taskRecorder
# noinspection PyUnresolvedReferences
@@ -34,9 +32,6 @@ import app.assets.resources
from app.services.core_service import coreService
from app.services.feature_service import featureService
-logger.add(f"{appLocalDataLocation}/GhostDownloader/GhostDownloader.log", rotation="512 KB", enqueue=True)
-logger.info(f"Ghost Downloader v{VERSION} is Launched at {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}")
-
warnings.warn = logger.warning
# internationalization
diff --git a/app/supports/application.py b/app/supports/application.py
index 0962204c..ac29c2bc 100644
--- a/app/supports/application.py
+++ b/app/supports/application.py
@@ -1,10 +1,12 @@
import sys
import traceback
+from time import localtime, strftime, time
-from PySide6.QtCore import QSharedMemory, QEvent
+from PySide6.QtCore import QSharedMemory, QEvent, QStandardPaths
from PySide6.QtWidgets import QApplication
from loguru import logger
+from app.supports.config import VERSION
from app.supports.signal_bus import signalBus
@@ -14,6 +16,11 @@ class SingletonApplication(QApplication):
super().__init__(argv)
self.key = key
+ appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppLocalDataLocation)
+ logger.add(f"{appLocalDataLocation}/GhostDownloader/GhostDownloader.log", rotation="512 KB", enqueue=True)
+ logger.info(
+ f"Ghost Downloader v{VERSION} is Launched at {strftime('%Y-%m-%d %H:%M:%S', localtime(time()))}")
+
# cleanup (only needed for unix)
try:
cleanupMemory = QSharedMemory(key)