Fix pythonw logging handler crashes and reduce noisy dependency logs

This commit is contained in:
nmemmert committed 2026-02-25 18:11:40 +00:00
1 parent 3e4ce93824
commit c0ebe118cb
2 files changed
+41 -2

No files matched your search

+20 -1
View File
@@ -25,7 +25,26 @@ except Exception as gui_import_error:
print("Then run: pip install -r requirements.txt")
sys.exit(1)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def configure_logging():
"""Configure logging with safe handlers for pythonw/GUI environments."""
log_format = '%(asctime)s - %(levelname)s - %(message)s'
handlers = []
try:
handlers.append(logging.FileHandler('app_log.txt', encoding='utf-8'))
except Exception:
pass
stream = getattr(sys, 'stderr', None) or getattr(sys, 'stdout', None)
if stream is not None:
handlers.append(logging.StreamHandler(stream))
logging.basicConfig(level=logging.INFO, format=log_format, handlers=handlers, force=True)
for noisy_logger in ('webdriver_manager', 'matplotlib', 'urllib3', 'plexapi'):
logging.getLogger(noisy_logger).setLevel(logging.WARNING)
configure_logging()
logger = logging.getLogger(__name__)
class Config:
+21 -1
View File
@@ -8,6 +8,7 @@ creates a playlist of matching songs, and imports it into Plex.
"""
import time
import sys
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
@@ -33,7 +34,26 @@ PLEX_TOKEN = os.getenv('PLEX_TOKEN', '').strip()
SERVER_IP = os.getenv('SERVER_IP', '').strip()
PLAYLIST_NAME = os.getenv('PLAYLIST_NAME', 'Journey FM Holiday').strip()
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def configure_logging():
"""Configure logging with safe handlers for pythonw/GUI environments."""
log_format = '%(asctime)s - %(levelname)s - %(message)s'
handlers = []
try:
handlers.append(logging.FileHandler('playlist_log.txt', encoding='utf-8'))
except Exception:
pass
stream = getattr(sys, 'stderr', None) or getattr(sys, 'stdout', None)
if stream is not None:
handlers.append(logging.StreamHandler(stream))
logging.basicConfig(level=logging.INFO, format=log_format, handlers=handlers, force=True)
for noisy_logger in ('webdriver_manager', 'matplotlib', 'urllib3', 'plexapi'):
logging.getLogger(noisy_logger).setLevel(logging.WARNING)
configure_logging()
logger = logging.getLogger(__name__)
def detect_chrome_binary():