diff --git a/backend/endpoints/search.py b/backend/endpoints/search.py index 6dc15bfc0..e8cfea6a6 100644 --- a/backend/endpoints/search.py +++ b/backend/endpoints/search.py @@ -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] = [] diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index d87525d84..57d9fb55e 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -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()] diff --git a/backend/handler/redis_handler.py b/backend/handler/redis_handler.py index 22bfea2df..423e680dc 100644 --- a/backend/handler/redis_handler.py +++ b/backend/handler/redis_handler.py @@ -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 diff --git a/backend/handler/scan_handler.py b/backend/handler/scan_handler.py index 9385234ab..482a3d166 100644 --- a/backend/handler/scan_handler.py +++ b/backend/handler/scan_handler.py @@ -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:" ) ) diff --git a/backend/logger/formatter.py b/backend/logger/formatter.py index 4c7652937..3910be5d0 100644 --- a/backend/logger/formatter.py +++ b/backend/logger/formatter.py @@ -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 diff --git a/backend/worker.py b/backend/worker.py index d890e54a3..ab12b40be 100644 --- a/backend/worker.py +++ b/backend/worker.py @@ -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 diff --git a/docker/init_scripts/init b/docker/init_scripts/init index ce4b41f21..0b69eeab2 100755 --- a/docker/init_scripts/init +++ b/docker/init_scripts/init @@ -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' diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf index 5e554f9c5..6ba62366c 100644 --- a/docker/nginx/default.conf +++ b/docker/nginx/default.conf @@ -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;