1
0
Fork 0
mirror of synced 2024-06-17 10:04:43 +12:00

App: Log both to file and to stderr

This commit is contained in:
Stelios Tsampas 2022-09-08 02:13:10 +03:00
parent d5d795ce79
commit 7ebeee0d1e
3 changed files with 18 additions and 9 deletions

View file

@ -54,15 +54,24 @@ class App(RareApp):
def __init__(self, args: Namespace):
super(App, self).__init__(args)
paths.create_dirs()
start_time = time.strftime("%y-%m-%d--%H-%M") # year-month-day-hour-minute
file_name = os.path.join(paths.log_dir(), f"Rare_{start_time}.log")
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
stream_handler = logging.StreamHandler(sys.stderr)
stream_handler.setFormatter(fmt=logging.Formatter("[%(name)s] %(levelname)s: %(message)s"))
# configure logging
if args.debug:
logging.basicConfig(
format="[%(name)s] %(levelname)s: %(message)s", level=logging.DEBUG
format="[%(name)s] %(levelname)s: %(message)s",
level=logging.DEBUG,
filename=file_name,
)
stream_handler.setLevel(logging.DEBUG)
logging.root.addHandler(stream_handler)
logging.getLogger().setLevel(level=logging.DEBUG)
# keep requests, asyncio and pillow quiet
logging.getLogger("requests").setLevel(logging.WARNING)
@ -76,12 +85,13 @@ class App(RareApp):
f" - Qt version: {QT_VERSION_STR}, PyQt version: {PYQT_VERSION_STR}"
)
else:
print(file_name)
logging.basicConfig(
format="[%(name)s] %(levelname)s: %(message)s",
level=logging.INFO,
filename=file_name,
)
stream_handler.setLevel(logging.INFO)
logging.root.addHandler(stream_handler)
logger.info(f"Launching Rare version {rare.__version__}")
logger.info(f"Operating System: {platform.system()}")

View file

@ -16,7 +16,6 @@ for old_dir in [
if old_dir.exists():
# lk: case-sensitive matching on Winblows
if old_dir.stem in os.listdir(old_dir.parent):
print(old_dir)
shutil.rmtree(old_dir, ignore_errors=True)

View file

@ -2,9 +2,8 @@ import os
import sys
from argparse import Namespace
from logging import getLogger
from pathlib import Path
from PyQt5.QtCore import Qt, QSettings, QTranslator, QStandardPaths
from PyQt5.QtCore import Qt, QSettings, QTranslator
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication
@ -12,7 +11,7 @@ from PyQt5.QtWidgets import QApplication
from legendary.core import LegendaryCore
import rare.resources.resources
from rare.utils.paths import resources_path
from rare.utils import paths
from rare.utils.misc import set_color_pallete, set_style_sheet
@ -27,6 +26,7 @@ class RareApp(QApplication):
self.setApplicationName("Rare")
self.setOrganizationName("Rare")
paths.create_dirs()
self.settings = QSettings()
# Translator
@ -53,7 +53,7 @@ class RareApp(QApplication):
self.setWindowIcon(QIcon(":/images/Rare.png"))
def load_translator(self, lang: str):
if os.path.isfile(f := os.path.join(resources_path, "languages", f"{lang}.qm")):
if os.path.isfile(f := os.path.join(paths.resources_path, "languages", f"{lang}.qm")):
self.translator.load(f)
self.logger.info(f"Your language is supported: {lang}")
elif not lang == "en":
@ -61,7 +61,7 @@ class RareApp(QApplication):
self.installTranslator(self.translator)
# translator for qt stuff
if os.path.isfile(f := os.path.join(resources_path, f"qt_{lang}.qm")):
if os.path.isfile(f := os.path.join(paths.resources_path, f"qt_{lang}.qm")):
self.qt_translator = QTranslator()
self.qt_translator.load(f)
self.installTranslator(self.qt_translator)