refactor: enhance logging messages and formatting for improved clarity and consistency

This commit is contained in:
zurdi
2025-05-08 23:35:33 +00:00
parent 49ad99d5e7
commit 53f9386208
8 changed files with 30 additions and 20 deletions

View File

@@ -18,6 +18,8 @@ from handler.metadata.moby_handler import MOBY_API_ENABLED, MobyGamesRom
from handler.metadata.sgdb_handler import STEAMGRIDDB_API_ENABLED
from handler.metadata.ss_handler import SS_API_ENABLED, SSRom
from handler.scan_handler import _get_main_platform_igdb_id
from logger.formatter import BLUE
from logger.formatter import highlight as hl
from logger.logger import log
from utils.router import APIRouter
@@ -68,8 +70,12 @@ async def search_rom(
)
matched_roms: list = []
log.info(f"Searching by {search_by.lower()}: {search_term}")
log.info(emoji.emojize(f":video_game: {rom.platform_slug}: {rom.fs_name}"))
log.info(f"Searching by {search_by.lower()}:")
log.info(
emoji.emojize(
f":video_game: {hl(rom.platform_display_name, color=BLUE)}[{rom.platform_fs_slug}]: {hl(search_term)}[{rom.fs_name}]"
)
)
igdb_matched_roms: list[IGDBRom] = []
moby_matched_roms: list[MobyGamesRom] = []

View File

@@ -181,7 +181,7 @@ async def scan_platforms(
if len(platform_list) == 0:
log.warning(
emoji.emojize(
f"{hl(':warning:', color=LIGHTYELLOW)} No platforms found, verify that the folder structure is right and the volume is mounted correctly. \
f"{hl(':warning:', color=LIGHTYELLOW)} No platforms found, verify that the folder structure is right and the volume is mounted correctly. \
Check https://github.com/rommapp/romm?tab=readme-ov-file#folder-structure for more details."
)
)
@@ -208,7 +208,7 @@ async def scan_platforms(
for p in purged_platforms:
log.info(f" - {p.slug}")
log.info(emoji.emojize(":check_mark: Scan completed "))
log.info(emoji.emojize(" :check_mark: Scan completed "))
await sm.emit("scan:done", scan_stats.__dict__)
except ScanStoppedException:
await stop_scan()
@@ -273,7 +273,7 @@ async def _identify_platform(
if len(fs_firmware) == 0:
log.warning(
emoji.emojize(
f" {hl(':warning:', color=LIGHTYELLOW)} No firmware found, skipping firmware scan for this platform"
f" {hl(':warning:', color=LIGHTYELLOW)} No firmware found, skipping firmware scan for this platform"
)
)
else:
@@ -295,7 +295,7 @@ async def _identify_platform(
if len(fs_roms) == 0:
log.warning(
emoji.emojize(
f" {hl(':warning:', color=LIGHTYELLOW)} No roms found, verify that the folder structure is correct"
f" {hl(':warning:', color=LIGHTYELLOW)} No roms found, verify that the folder structure is correct"
)
)
else:
@@ -539,7 +539,7 @@ async def scan_handler(_sid: str, options: dict):
options (dict): Socket options
"""
log.info(emoji.emojize(":magnifying_glass_tilted_right: Scanning "))
log.info(emoji.emojize(":magnifying_glass_tilted_right: Scanning"))
platform_ids = options.get("platforms", [])
scan_type = ScanType[options.get("type", "quick").upper()]

View File

@@ -1,3 +1,4 @@
import os
import sys
from enum import Enum
@@ -30,7 +31,9 @@ def __get_sync_cache() -> Redis:
# A separate client that auto-decodes responses is needed
client = Redis.from_url(str(REDIS_URL), decode_responses=True)
log.debug(f"Sync redis/valkey connection established in {sys.argv[0]}")
log.debug(
f"Sync redis/valkey connection established in {os.path.splitext(os.path.basename(sys.argv[0]))[0]}"
)
return client
@@ -43,7 +46,9 @@ def __get_async_cache() -> AsyncRedis:
# A separate client that auto-decodes responses is needed
client = AsyncRedis.from_url(str(REDIS_URL), decode_responses=True)
log.debug(f"Async redis/valkey connection established in {sys.argv[0]}")
log.debug(
f"Async redis/valkey connection established in {os.path.splitext(os.path.basename(sys.argv[0]))[0]}"
)
return client

View File

@@ -68,7 +68,7 @@ async def scan_platform(
Platform object
"""
log.info(f"· {hl(fs_slug)}")
log.info(f"· Found {hl(fs_slug)} folder")
if metadata_sources is None:
metadata_sources = [MetadataSource.IGDB, MetadataSource.MOBY, MetadataSource.SS]
@@ -138,7 +138,7 @@ async def scan_platform(
else:
log.warning(
emoji.emojize(
f" Platform {platform_attrs['slug']} not identified :cross_mark:"
f" Platform {platform_attrs['slug']} not identified :cross_mark:"
)
)

View File

@@ -1,5 +1,4 @@
import logging
import os
from colorama import Fore, Style, init
from config import FORCE_COLOR, NO_COLOR
@@ -26,9 +25,8 @@ def should_strip_ansi() -> bool:
return False
if NO_COLOR:
return True
# For other environments, strip colors if not a TTY
return not os.isatty(1)
# Default: do not strip (Docker will handle colors)
return False
# Initialize Colorama once, considering different environments

View File

@@ -14,8 +14,9 @@ sentry_sdk.init(
release=f"romm@{get_version()}",
)
# TODO: setup custom logger for background workers
# Set up custom logging for Worker logging
logging.basicConfig(format=common_log_format, datefmt=common_date_format)
# logging.basicConfig(format=common_log_format, datefmt=common_date_format)
if __name__ == "__main__":
# Start the worker

View File

@@ -19,7 +19,6 @@ REDIS_HOST="${REDIS_HOST:=""}"
# (since backend is almost 100% async this won't block anything)
DEFAULT_WEB_CONCURRENCY=1
# TODO: disable colors for non-TTY terminal
# logger colors
RED='\033[0;31m'
LIGHTMAGENTA='\033[0;95m'

View File

@@ -63,9 +63,10 @@ http {
}
#INFO: [nginx][2023-11-14 09:20:29] 127.0.0.1 - -"GET / HTTP/1.1" 500 177 "-" "Mozilla/5.0 (X11; Linux x86_64)"rt=0.000 uct="-" uht="-" urt="-"
log_format romm_logs 'INFO: [RomM][nginx][$date $time] $remote_addr | $http_x_forwarded_for | '
'$request_method $request_uri | $status | $body_bytes_sent | '
'$browser $os | $request_time';
log_format romm_logs 'INFO: [RomM][nginx][$date $time] '
'$remote_addr | $http_x_forwarded_for | '
'$request_method $request_uri $status | $body_bytes_sent | '
'$browser $os | $request_time';
access_log /dev/stdout romm_logs;
error_log /dev/stderr;