mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
refactor: improve logging messages and formatting for clarity and consistency across multiple modules
This commit is contained in:
@@ -86,7 +86,9 @@ async def add_rom(request: Request):
|
||||
|
||||
platform_fs_slug = db_platform.fs_slug
|
||||
roms_path = fs_rom_handler.build_upload_fs_path(platform_fs_slug)
|
||||
log.info(f"Uploading file to {hl(platform_fs_slug)}")
|
||||
log.info(
|
||||
f"Uploading file to {hl(db_platform.custom_name or db_platform.name, color=BLUE)}[{hl(platform_fs_slug)}]"
|
||||
)
|
||||
|
||||
file_location = Path(f"{roms_path}/{filename}")
|
||||
parser = StreamingFormDataParser(headers=request.headers)
|
||||
|
||||
@@ -33,7 +33,7 @@ from handler.scan_handler import (
|
||||
scan_rom,
|
||||
)
|
||||
from handler.socket_handler import socket_handler
|
||||
from logger.formatter import LIGHTYELLOW, RED
|
||||
from logger.formatter import BLUE, LIGHTYELLOW, RED
|
||||
from logger.formatter import highlight as hl
|
||||
from logger.logger import log
|
||||
from models.platform import Platform
|
||||
@@ -186,7 +186,9 @@ async def scan_platforms(
|
||||
)
|
||||
)
|
||||
else:
|
||||
log.info(f"Found {hl(len(platform_list))} platforms in the file system")
|
||||
log.info(
|
||||
f"Found {hl(str(len(platform_list)))} platforms in the file system"
|
||||
)
|
||||
|
||||
for platform_slug in platform_list:
|
||||
scan_stats += await _identify_platform(
|
||||
@@ -273,11 +275,11 @@ 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 for {hl(platform.custom_name or platform.name, color=BLUE)}[{hl(platform.fs_slug)}]"
|
||||
)
|
||||
)
|
||||
else:
|
||||
log.info(f" {hl(len(fs_firmware))} firmware files found")
|
||||
log.info(f"{hl(str(len(fs_firmware)))} firmware files found")
|
||||
|
||||
for fs_fw in fs_firmware:
|
||||
scan_stats += await _identify_firmware(
|
||||
@@ -295,11 +297,11 @@ 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:
|
||||
log.info(f" {hl(len(fs_roms))} roms found in the file system")
|
||||
log.info(f"{hl(str(len(fs_roms)))} roms found in the file system")
|
||||
|
||||
for fs_roms_batch in batched(fs_roms, 200):
|
||||
rom_by_filename_map = db_rom_handler.get_roms_by_fs_name(
|
||||
|
||||
@@ -11,7 +11,7 @@ from handler.metadata import meta_igdb_handler, meta_moby_handler, meta_ss_handl
|
||||
from handler.metadata.igdb_handler import IGDBPlatform, IGDBRom
|
||||
from handler.metadata.moby_handler import MobyGamesPlatform, MobyGamesRom
|
||||
from handler.metadata.ss_handler import SSPlatform, SSRom
|
||||
from logger.formatter import BLUE
|
||||
from logger.formatter import BLUE, LIGHTYELLOW
|
||||
from logger.formatter import highlight as hl
|
||||
from logger.logger import log
|
||||
from models.assets import Save, Screenshot, State
|
||||
@@ -68,8 +68,6 @@ async def scan_platform(
|
||||
Platform object
|
||||
"""
|
||||
|
||||
log.info(f"· Found {hl(fs_slug, color=BLUE)} folder")
|
||||
|
||||
if metadata_sources is None:
|
||||
metadata_sources = [MetadataSource.IGDB, MetadataSource.MOBY, MetadataSource.SS]
|
||||
|
||||
@@ -83,7 +81,7 @@ async def scan_platform(
|
||||
# Sometimes users change the name of the folder, so we try to match it with the config
|
||||
if fs_slug not in fs_platforms:
|
||||
log.warning(
|
||||
f" {hl(fs_slug)} not found in file system, trying to match via config..."
|
||||
f"{hl(fs_slug)} not found in file system, trying to match via config"
|
||||
)
|
||||
if fs_slug in swapped_platform_bindings.keys():
|
||||
platform = db_platform_handler.get_platform_by_fs_slug(fs_slug)
|
||||
@@ -132,13 +130,13 @@ async def scan_platform(
|
||||
):
|
||||
log.info(
|
||||
emoji.emojize(
|
||||
f" Identified as {hl(platform_attrs['name'], color=BLUE)} :video_game:"
|
||||
f"Folder {hl(platform_attrs['fs_slug'])}[{hl(fs_slug)}] identified as {hl(platform_attrs['name'], color=BLUE)} :video_game:"
|
||||
)
|
||||
)
|
||||
else:
|
||||
log.warning(
|
||||
emoji.emojize(
|
||||
f" Platform {hl(platform_attrs['slug'])} not identified :cross_mark:"
|
||||
f"Platform {hl(platform_attrs['slug'])} not identified :cross_mark:"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -202,12 +200,6 @@ async def scan_rom(
|
||||
|
||||
roms_path = fs_rom_handler.get_roms_fs_structure(platform.fs_slug)
|
||||
|
||||
log.info(f"\t · {hl(fs_rom['fs_name'])}")
|
||||
|
||||
if fs_rom.get("multi", False):
|
||||
for file in fs_rom["files"]:
|
||||
log.info(f"\t\t · {file.file_name}")
|
||||
|
||||
# Set default properties
|
||||
rom_attrs = {
|
||||
"id": rom.id if rom else None,
|
||||
@@ -348,23 +340,24 @@ async def scan_rom(
|
||||
and not ss_handler_rom.get("ss_id")
|
||||
):
|
||||
log.warning(
|
||||
emoji.emojize(
|
||||
f"\t Rom {hl(rom_attrs['fs_name'])} not identified :cross_mark:"
|
||||
)
|
||||
emoji.emojize(f"{hl(rom_attrs['fs_name'])} not identified :cross_mark:")
|
||||
)
|
||||
return Rom(**rom_attrs)
|
||||
|
||||
log.info(
|
||||
emoji.emojize(
|
||||
f"\t Identified as {hl(rom_attrs['name'], color=BLUE)} :alien_monster:"
|
||||
f"{hl(rom_attrs['fs_name'])} identified as {hl(rom_attrs['name'], color=BLUE)} :alien_monster:"
|
||||
)
|
||||
)
|
||||
if fs_rom.get("multi", False):
|
||||
for file in fs_rom["files"]:
|
||||
log.info(f"\t · {hl(file.file_name, color=LIGHTYELLOW)}")
|
||||
|
||||
return Rom(**rom_attrs)
|
||||
|
||||
|
||||
def _scan_asset(file_name: str, path: str):
|
||||
log.info(f"\t\t · {hl(file_name)}")
|
||||
log.info(f"\t · {hl(file_name)}")
|
||||
|
||||
file_size = fs_asset_handler.get_asset_size(file_name=file_name, asset_path=path)
|
||||
|
||||
|
||||
@@ -48,8 +48,6 @@ error_log() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# TODO: check on database disconnection
|
||||
|
||||
wait_for_gunicorn_socket() {
|
||||
debug_log "Waiting for gunicorn socket file..."
|
||||
local retries=60
|
||||
@@ -80,8 +78,8 @@ start_bin_gunicorn() {
|
||||
fi
|
||||
|
||||
gunicorn \
|
||||
--error-logfile /tmp/gunicorn_access.log \
|
||||
--error-logfile /tmp/gunicorn_error.log \
|
||||
--error-logfile - \
|
||||
--error-logfile - \
|
||||
--worker-class uvicorn.workers.UvicornWorker \
|
||||
--bind=0.0.0.0:5000 \
|
||||
--bind=unix:/tmp/gunicorn.sock \
|
||||
|
||||
Reference in New Issue
Block a user