diff --git a/xradios/__init__.py b/xradios/__init__.py index 28e193e..6330707 100644 --- a/xradios/__init__.py +++ b/xradios/__init__.py @@ -1 +1,34 @@ +import os +import logging + +from appdirs import user_log_dir +from appdirs import user_data_dir +from appdirs import user_config_dir + +from pathlib import Path + __version__ = "0.0.1.dev6" + +app_name = "xradios" + +xradios_config_dir = Path(user_config_dir(appname=app_name)) +xradios_config_dir.mkdir(parents=True, exist_ok=True) + +xradios_data_dir = Path(user_data_dir(appname=app_name)) +xradios_data_dir.mkdir(parents=True, exist_ok=True) + +xradios_log_dir = Path(user_log_dir(appname=app_name)) +xradios_log_dir.mkdir(parents=True, exist_ok=True) + +log_level = getattr(logging, os.environ.get("XRADIOS_LOG_LEVEL", "INFO")) + +if log_level == logging.DEBUG: + log_format = "%(levelname)s - %(name)s - %(module)s - %(funcName)s - %(message)s" +else: + log_format = "%(levelname)s - %(name)s - %(message)s" + +log_file = "xradios.log" + +logging.basicConfig( + filename=xradios_log_dir / log_file, level=log_level, format=log_format +) diff --git a/xradios/core/server.py b/xradios/core/server.py index 756f9eb..4938474 100644 --- a/xradios/core/server.py +++ b/xradios/core/server.py @@ -1,17 +1,11 @@ import logging -import os import sys import signal -from pathlib import Path from xmlrpc.server import SimpleXMLRPCServer from xmlrpc.server import SimpleXMLRPCRequestHandler -from appdirs import user_data_dir -from appdirs import user_log_dir -from appdirs import user_config_dir - from pyradios import RadioBrowser from tinydb import Query @@ -19,33 +13,12 @@ from xradios.core.metadata import metadata_manager from xradios.core.player import player +from xradios import xradios_data_dir -app_name = 'xradios' -server_name = 'xradiosd' - -xradios_config_dir = Path(user_config_dir(appname=app_name)) -xradios_config_dir.mkdir(parents=True, exist_ok=True) - -xradios_data_dir = Path(user_data_dir(appname=app_name)) -xradios_data_dir.mkdir(parents=True, exist_ok=True) - -xradios_log_dir = Path(user_log_dir(appname=app_name)) -xradios_log_dir.mkdir(parents=True, exist_ok=True) - -log_level = getattr(logging, os.environ.get('XRADIOS_LOG_LEVEL', 'INFO')) -log_format = '%(levelname)s - %(name)s - %(message)s' -log_file = 'xradios.log' - -logging.basicConfig( - filename=xradios_log_dir / log_file, - level=log_level, - format=log_format - ) - -log = logging.getLogger('xradios') +log = logging.getLogger("xradiosd") effective_log_level = logging.getLevelName(log.getEffectiveLevel()) -log.info(f'Log level {effective_log_level=}') +log.info(f"Log level {effective_log_level=}") rb = RadioBrowser()