mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-12 23:37:14 +03:00
Merge pull request #2259 from HullSeals/enhancement/2215/move-logging-dir
[2215] Move Logging Directory
This commit is contained in:
commit
ac9b7b42bf
@ -41,7 +41,6 @@ import logging
|
|||||||
import logging.handlers
|
import logging.handlers
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import tempfile
|
|
||||||
import warnings
|
import warnings
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
@ -51,9 +50,7 @@ from threading import get_native_id as thread_native_id
|
|||||||
from time import gmtime
|
from time import gmtime
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
from typing import TYPE_CHECKING, cast
|
from typing import TYPE_CHECKING, cast
|
||||||
|
from config import appcmdname, appname, config, trace_on
|
||||||
import config as config_mod
|
|
||||||
from config import appcmdname, appname, config
|
|
||||||
|
|
||||||
# TODO: Tests:
|
# TODO: Tests:
|
||||||
#
|
#
|
||||||
@ -104,7 +101,7 @@ warnings.simplefilter('default', DeprecationWarning)
|
|||||||
|
|
||||||
|
|
||||||
def _trace_if(self: logging.Logger, condition: str, message: str, *args, **kwargs) -> None:
|
def _trace_if(self: logging.Logger, condition: str, message: str, *args, **kwargs) -> None:
|
||||||
if any(fnmatch(condition, p) for p in config_mod.trace_on):
|
if any(fnmatch(condition, p) for p in trace_on):
|
||||||
self._log(logging.TRACE, message, args, **kwargs) # type: ignore # we added it
|
self._log(logging.TRACE, message, args, **kwargs) # type: ignore # we added it
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -184,8 +181,7 @@ class Logger:
|
|||||||
# We want the files in %TEMP%\{appname}\ as {logger_name}-debug.log and
|
# We want the files in %TEMP%\{appname}\ as {logger_name}-debug.log and
|
||||||
# rotated versions.
|
# rotated versions.
|
||||||
# This is {logger_name} so that EDMC.py logs to a different file.
|
# This is {logger_name} so that EDMC.py logs to a different file.
|
||||||
logfile_rotating = pathlib.Path(tempfile.gettempdir())
|
logfile_rotating = pathlib.Path(config.app_dir_path / 'logs')
|
||||||
logfile_rotating /= f'{appname}'
|
|
||||||
logfile_rotating.mkdir(exist_ok=True)
|
logfile_rotating.mkdir(exist_ok=True)
|
||||||
logfile_rotating /= f'{logger_name}-debug.log'
|
logfile_rotating /= f'{logger_name}-debug.log'
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import tempfile
|
|
||||||
from os import chdir, environ, path
|
from os import chdir, environ, path
|
||||||
from time import localtime, strftime, time
|
from time import localtime, strftime, time
|
||||||
from typing import TYPE_CHECKING, Any, Literal
|
from typing import TYPE_CHECKING, Any, Literal
|
||||||
@ -42,16 +41,19 @@ else:
|
|||||||
# not frozen.
|
# not frozen.
|
||||||
chdir(pathlib.Path(__file__).parent)
|
chdir(pathlib.Path(__file__).parent)
|
||||||
|
|
||||||
|
|
||||||
# config will now cause an appname logger to be set up, so we need the
|
# config will now cause an appname logger to be set up, so we need the
|
||||||
# console redirect before this
|
# console redirect before this
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Keep this as the very first code run to be as sure as possible of no
|
# Keep this as the very first code run to be as sure as possible of no
|
||||||
# output until after this redirect is done, if needed.
|
# output until after this redirect is done, if needed.
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
|
from config import config
|
||||||
# By default py2exe tries to write log to dirname(sys.executable) which fails when installed
|
# By default py2exe tries to write log to dirname(sys.executable) which fails when installed
|
||||||
# unbuffered not allowed for text in python3, so use `1 for line buffering
|
# unbuffered not allowed for text in python3, so use `1 for line buffering
|
||||||
log_file_path = path.join(tempfile.gettempdir(), f'{appname}.log')
|
log_file_path = pathlib.Path(config.app_dir_path / 'logs')
|
||||||
|
log_file_path.mkdir(exist_ok=True)
|
||||||
|
log_file_path /= f'{appname}.log'
|
||||||
|
|
||||||
sys.stdout = sys.stderr = open(log_file_path, mode='wt', buffering=1) # Do NOT use WITH here.
|
sys.stdout = sys.stderr = open(log_file_path, mode='wt', buffering=1) # Do NOT use WITH here.
|
||||||
# TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup
|
# TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup
|
||||||
|
|
||||||
@ -619,7 +621,7 @@ class AppWindow:
|
|||||||
self.help_menu.add_command(command=lambda: self.updater.check_for_updates()) # Check for Updates...
|
self.help_menu.add_command(command=lambda: self.updater.check_for_updates()) # Check for Updates...
|
||||||
# About E:D Market Connector
|
# About E:D Market Connector
|
||||||
self.help_menu.add_command(command=lambda: not self.HelpAbout.showing and self.HelpAbout(self.w))
|
self.help_menu.add_command(command=lambda: not self.HelpAbout.showing and self.HelpAbout(self.w))
|
||||||
logfile_loc = pathlib.Path(tempfile.gettempdir()) / appname
|
logfile_loc = pathlib.Path(config.app_dir_path / 'logs')
|
||||||
self.help_menu.add_command(command=lambda: prefs.open_folder(logfile_loc)) # Open Log Folder
|
self.help_menu.add_command(command=lambda: prefs.open_folder(logfile_loc)) # Open Log Folder
|
||||||
self.help_menu.add_command(command=lambda: prefs.help_open_system_profiler(self)) # Open Log Folde
|
self.help_menu.add_command(command=lambda: prefs.help_open_system_profiler(self)) # Open Log Folde
|
||||||
|
|
||||||
|
@ -4,20 +4,18 @@ from __future__ import annotations
|
|||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
import tempfile
|
|
||||||
import threading
|
import threading
|
||||||
import zlib
|
import zlib
|
||||||
from http import server
|
from http import server
|
||||||
from typing import Any, Callable, Literal
|
from typing import Any, Callable, Literal
|
||||||
from urllib.parse import parse_qs
|
from urllib.parse import parse_qs
|
||||||
|
import config
|
||||||
from config import appname
|
|
||||||
from EDMCLogging import get_main_logger
|
from EDMCLogging import get_main_logger
|
||||||
|
|
||||||
logger = get_main_logger()
|
logger = get_main_logger()
|
||||||
|
|
||||||
output_lock = threading.Lock()
|
output_lock = threading.Lock()
|
||||||
output_data_path = pathlib.Path(tempfile.gettempdir()) / f'{appname}' / 'http_debug'
|
output_data_path = pathlib.Path(config.app_dir_path / 'logs' / 'http_debug')
|
||||||
SAFE_TRANSLATE = str.maketrans(dict.fromkeys("!@#$%^&*()./\\\r\n[]-+='\";:?<>,~`", '_'))
|
SAFE_TRANSLATE = str.maketrans(dict.fromkeys("!@#$%^&*()./\\\r\n[]-+='\";:?<>,~`", '_'))
|
||||||
|
|
||||||
|
|
||||||
|
6
prefs.py
6
prefs.py
@ -7,7 +7,6 @@ import logging
|
|||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import warnings
|
import warnings
|
||||||
from os import system
|
from os import system
|
||||||
@ -20,7 +19,6 @@ import myNotebook as nb # noqa: N813
|
|||||||
import plug
|
import plug
|
||||||
from config import appversion_nobuild, config
|
from config import appversion_nobuild, config
|
||||||
from EDMCLogging import edmclogger, get_main_logger
|
from EDMCLogging import edmclogger, get_main_logger
|
||||||
from constants import appname
|
|
||||||
from hotkey import hotkeymgr
|
from hotkey import hotkeymgr
|
||||||
from l10n import translations as tr
|
from l10n import translations as tr
|
||||||
from monitor import monitor
|
from monitor import monitor
|
||||||
@ -43,7 +41,7 @@ def help_open_log_folder() -> None:
|
|||||||
"""Open the folder logs are stored in."""
|
"""Open the folder logs are stored in."""
|
||||||
warnings.warn('prefs.help_open_log_folder is deprecated, use open_log_folder instead. '
|
warnings.warn('prefs.help_open_log_folder is deprecated, use open_log_folder instead. '
|
||||||
'This function will be removed in 6.0 or later', DeprecationWarning, stacklevel=2)
|
'This function will be removed in 6.0 or later', DeprecationWarning, stacklevel=2)
|
||||||
open_folder(pathlib.Path(tempfile.gettempdir()) / appname)
|
open_folder(pathlib.Path(config.app_dir_path / 'logs'))
|
||||||
|
|
||||||
|
|
||||||
def open_folder(file: pathlib.Path) -> None:
|
def open_folder(file: pathlib.Path) -> None:
|
||||||
@ -324,7 +322,7 @@ class PreferencesDialog(tk.Toplevel):
|
|||||||
self.geometry(f"+{position.left}+{position.top}")
|
self.geometry(f"+{position.left}+{position.top}")
|
||||||
|
|
||||||
# Set Log Directory
|
# Set Log Directory
|
||||||
self.logfile_loc = pathlib.Path(tempfile.gettempdir()) / appname
|
self.logfile_loc = pathlib.Path(config.app_dir_path / 'logs')
|
||||||
|
|
||||||
# Set minimum size to prevent content cut-off
|
# Set minimum size to prevent content cut-off
|
||||||
self.update_idletasks() # Update "requested size" from geometry manager
|
self.update_idletasks() # Update "requested size" from geometry manager
|
||||||
|
Loading…
x
Reference in New Issue
Block a user