Merge pull request #323 from maxdorninger/reduce-amount-of-logs

Reduce amount of logs and add log level variable
This commit is contained in:
Maximilian Dorninger
2025-12-29 12:18:44 +01:00
committed by GitHub
9 changed files with 46 additions and 100 deletions

View File

@@ -8,4 +8,10 @@ the console (stdout) by default, and to a json-formatted log file.
The location of the log file can be configured with the `LOG_FILE` environment variable. By default, the log file is
located at
`/app/config/media_manager.log`. When changing the log file location, ensure that the directory exists, is writable by the
MediaManager container and that it is a full path.
MediaManager container and that it is a full path.
With the `MEDIAMANAGER_LOG_LEVEL` environment variable, you can set the logging level. The available levels are:
- `DEBUG` - Detailed information, typically of interest only when diagnosing problems.
- `INFO` - The default level, for general operational entries about what's going on inside the application.
- `WARNING`
- `ERROR`

View File

@@ -34,6 +34,7 @@ services:
- MEDIAMANAGER_MISC__CORS_URLS=["http://localhost:5173"]
- DISABLE_FRONTEND_MOUNT=TRUE
- LOG_FILE=/dev/null
- MEDIAMANAGER_LOG_LEVEL=DEBUG
volumes:
#- ./web/build:/app/web/build # this is only needed to test built frontend when developing frontend
- ./res/images/:/data/images/
@@ -60,33 +61,33 @@ services:
# Additional services can be uncommented and configured as needed
# ----------------------------
# prowlarr:
# image: lscr.io/linuxserver/prowlarr:latest
# container_name: prowlarr
# environment:
# - PUID=1000
# - PGID=1000
# - TZ=Etc/UTC
# volumes:
# - ./res/prowlarr:/config
# restart: unless-stopped
# ports:
# - "9696:9696"
# qbittorrent:
# image: lscr.io/linuxserver/qbittorrent:latest
# container_name: qbittorrent
# environment:
# - TZ=Etc/UTC
# - WEBUI_PORT=8080
# - TORRENTING_PORT=6881
# ports:
# - 8080:8080
# - 6881:6881
# - 6881:6881/udp
# restart: unless-stopped
# volumes:
# - ./res/torrents:/download
# - ./res/qbittorrent:/config
prowlarr:
image: lscr.io/linuxserver/prowlarr:latest
container_name: prowlarr
environment:
- PUID=1000
- PGID=1000
- TZ=Etc/UTC
volumes:
- ./res/prowlarr:/config
restart: unless-stopped
ports:
- "9696:9696"
qbittorrent:
image: lscr.io/linuxserver/qbittorrent:latest
container_name: qbittorrent
environment:
- TZ=Etc/UTC
- WEBUI_PORT=8080
- TORRENTING_PORT=6881
ports:
- 8080:8080
- 6881:6881
- 6881:6881/udp
restart: unless-stopped
volumes:
- ./res/torrents:/download
- ./res/qbittorrent:/config
# transmission:
# image: lscr.io/linuxserver/transmission:latest
# container_name: transmission

View File

@@ -13,7 +13,7 @@ class ISOJsonFormatter(JsonFormatter):
return dt.isoformat(timespec="milliseconds").replace("+00:00", "Z")
LOG_LEVEL = logging.DEBUG
LOG_LEVEL = os.getenv("MEDIAMANAGER_LOG_LEVEL", "INFO").upper()
LOG_FILE = Path(os.getenv("LOG_FILE", "/app/config/media_manager.log"))
LOGGING_CONFIG = {
"version": 1,

View File

@@ -156,8 +156,10 @@ class MovieService:
)
for torrent in torrents:
try:
self.torrent_service.cancel_download(torrent, delete_files=True)
log.info(f"Deleted torrent: {torrent.hash}")
self.torrent_service.cancel_download(
torrent=torrent, delete_files=True
)
log.info(f"Deleted torrent: {torrent.torrent_title}")
except Exception as e:
log.warning(f"Failed to delete torrent {torrent.hash}: {e}")

View File

@@ -53,13 +53,11 @@ class QbittorrentDownloadClient(AbstractDownloadClient):
)
try:
self.api_client.auth_log_in()
log.info("Successfully logged into qbittorrent")
except Exception as e:
log.error(f"Failed to log into qbittorrent: {e}")
raise
try:
log.info("Trying to create MediaManager category in qBittorrent")
self.api_client.torrents_create_category(
name=self.config.category_name,
save_path=self.config.category_save_path
@@ -67,9 +65,6 @@ class QbittorrentDownloadClient(AbstractDownloadClient):
else None,
)
except Conflict409Error:
log.info(
"MediaManager category already exists in qBittorrent, modifying existing category to reflect current config."
)
try:
self.api_client.torrents_edit_category(
name=self.config.category_name,
@@ -78,11 +73,7 @@ class QbittorrentDownloadClient(AbstractDownloadClient):
else None,
)
except Exception as e:
if str(e) == "":
log.info(
"MediaManager category in qBittorrent is already up to date"
)
else:
if str(e) != "":
log.error(
f"Error on updating MediaManager category in qBittorrent, error: {e}"
)
@@ -94,13 +85,9 @@ class QbittorrentDownloadClient(AbstractDownloadClient):
:param indexer_result: The indexer query result of the torrent file to download.
:return: The torrent object with calculated hash and initial status.
"""
log.info(f"Attempting to download torrent: {indexer_result.title}")
torrent_hash = get_torrent_hash(torrent=indexer_result)
answer = None
log.info(
f"Downloading torrent {indexer_result.title} with download_url: {indexer_result.download_url}"
)
try:
self.api_client.auth_log_in()
answer = self.api_client.torrents_add(
@@ -158,7 +145,6 @@ class QbittorrentDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to get the status of.
:return: The status of the torrent.
"""
log.info(f"Fetching status for torrent: {torrent.title}")
try:
self.api_client.auth_log_in()
info = self.api_client.torrents_info(torrent_hashes=torrent.hash)
@@ -170,7 +156,6 @@ class QbittorrentDownloadClient(AbstractDownloadClient):
return TorrentStatus.unknown
else:
state: str = info[0]["state"]
log.info(f"Torrent {torrent.id} is in state: {state}")
if state in self.DOWNLOADING_STATE:
return TorrentStatus.downloading
@@ -189,7 +174,6 @@ class QbittorrentDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to pause.
"""
log.info(f"Pausing torrent: {torrent.title}")
try:
self.api_client.auth_log_in()
self.api_client.torrents_pause(torrent_hashes=torrent.hash)
@@ -202,7 +186,6 @@ class QbittorrentDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to resume.
"""
log.info(f"Resuming torrent: {torrent.title}")
try:
self.api_client.auth_log_in()
self.api_client.torrents_resume(torrent_hashes=torrent.hash)

View File

@@ -36,9 +36,7 @@ class SabnzbdDownloadClient(AbstractDownloadClient):
self.client._base_url = f"{self.config.host.rstrip('/')}:{self.config.port}{self.config.base_path}" # the library expects a /sabnzbd prefix for whatever reason
try:
# Test connection
version = self.client.version()
log.info(f"Successfully connected to SABnzbd version: {version}")
self.client.version()
except Exception as e:
log.error(f"Failed to connect to SABnzbd: {e}")
raise
@@ -50,8 +48,6 @@ class SabnzbdDownloadClient(AbstractDownloadClient):
:param indexer_result: The indexer query result of the NZB file to download.
:return: The torrent object with calculated hash and initial status.
"""
log.info(f"Attempting to download NZB: {indexer_result.title}")
try:
# Add NZB to SABnzbd queue
response = self.client.add_uri(
@@ -65,8 +61,6 @@ class SabnzbdDownloadClient(AbstractDownloadClient):
# Generate a hash for the NZB (using title and download URL)
nzo_id = response["nzo_ids"][0]
log.info(f"Successfully added NZB: {indexer_result.title}")
# Create and return torrent object
torrent = Torrent(
status=TorrentStatus.unknown,
@@ -93,10 +87,8 @@ class SabnzbdDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to remove.
:param delete_data: Whether to delete the downloaded files.
"""
log.info(f"Removing torrent: {torrent.title} (Delete data: {delete_data})")
try:
self.client.delete_job(nzo_id=torrent.hash, delete_files=delete_data)
log.info(f"Successfully removed torrent: {torrent.title}")
except Exception as e:
log.error(f"Failed to remove torrent {torrent.title}: {e}")
raise
@@ -107,10 +99,8 @@ class SabnzbdDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to pause.
"""
log.info(f"Pausing torrent: {torrent.title}")
try:
self.client.pause_job(nzo_id=torrent.hash)
log.info(f"Successfully paused torrent: {torrent.title}")
except Exception as e:
log.error(f"Failed to pause torrent {torrent.title}: {e}")
raise
@@ -121,10 +111,8 @@ class SabnzbdDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to resume.
"""
log.info(f"Resuming torrent: {torrent.title}")
try:
self.client.resume_job(nzo_id=torrent.hash)
log.info(f"Successfully resumed torrent: {torrent.title}")
except Exception as e:
log.error(f"Failed to resume torrent {torrent.title}: {e}")
raise
@@ -136,11 +124,8 @@ class SabnzbdDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to get the status of.
:return: The status of the torrent.
"""
log.info(f"Fetching status for download: {torrent.title}")
response = self.client.get_downloads(nzo_ids=torrent.hash)
log.debug("SABnzbd response: %s", response)
status = response["queue"]["status"]
log.info(f"Download status for NZB {torrent.title}: {status}")
return self._map_status(status)
def _map_status(self, sabnzbd_status: str) -> TorrentStatus:

View File

@@ -39,7 +39,6 @@ class TransmissionDownloadClient(AbstractDownloadClient):
)
# Test connection
self._client.session_stats()
log.info("Successfully connected to Transmission")
except Exception as e:
log.error(f"Failed to connect to Transmission: {e}")
raise
@@ -51,9 +50,7 @@ class TransmissionDownloadClient(AbstractDownloadClient):
:param indexer_result: The indexer query result of the torrent file to download.
:return: The torrent object with calculated hash and initial status.
"""
log.info(f"Attempting to download torrent: {indexer_result.title}")
torrent_hash = get_torrent_hash(torrent=indexer_result)
log.info(f"parsed torrent hash: {torrent_hash}")
download_dir = (
AllEncompassingConfig().misc.torrent_directory / indexer_result.title
)
@@ -91,11 +88,9 @@ class TransmissionDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to remove.
:param delete_data: Whether to delete the downloaded data.
"""
log.info(f"Removing torrent: {torrent.title}")
try:
self._client.remove_torrent(torrent.hash, delete_data=delete_data)
log.info(f"Successfully removed torrent: {torrent.title}")
except Exception as e:
log.error(f"Failed to remove torrent: {e}")
raise
@@ -107,7 +102,6 @@ class TransmissionDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to get the status of.
:return: The status of the torrent.
"""
log.debug(f"Fetching status for torrent: {torrent.title}")
try:
transmission_torrent = self._client.get_torrent(torrent.hash)
@@ -126,7 +120,6 @@ class TransmissionDownloadClient(AbstractDownloadClient):
f"Torrent {torrent.title} has error status: {transmission_torrent.error_string}"
)
log.debug(f"Torrent {torrent.title} status: {status}")
return status
except Exception as e:
@@ -139,11 +132,9 @@ class TransmissionDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to pause.
"""
log.info(f"Pausing torrent: {torrent.title}")
try:
self._client.stop_torrent(torrent.hash)
log.info(f"Successfully paused torrent: {torrent.title}")
log.debug(f"Successfully paused torrent: {torrent.title}")
except Exception as e:
log.error(f"Failed to pause torrent: {e}")
@@ -155,11 +146,9 @@ class TransmissionDownloadClient(AbstractDownloadClient):
:param torrent: The torrent to resume.
"""
log.info(f"Resuming torrent: {torrent.title}")
try:
self._client.start_torrent(torrent.hash)
log.info(f"Successfully resumed torrent: {torrent.title}")
log.debug(f"Successfully resumed torrent: {torrent.title}")
except Exception as e:
log.error(f"Failed to resume torrent: {e}")

View File

@@ -43,9 +43,6 @@ class DownloadManager:
if self.config.qbittorrent.enabled:
try:
self._torrent_client = QbittorrentDownloadClient()
log.info(
"qBittorrent client initialized and set as active torrent client"
)
except Exception as e:
log.error(f"Failed to initialize qBittorrent client: {e}")
@@ -53,9 +50,6 @@ class DownloadManager:
if self._torrent_client is None and self.config.transmission.enabled:
try:
self._torrent_client = TransmissionDownloadClient()
log.info(
"Transmission client initialized and set as active torrent client"
)
except Exception as e:
log.error(f"Failed to initialize Transmission client: {e}")
@@ -63,7 +57,6 @@ class DownloadManager:
if self.config.sabnzbd.enabled:
try:
self._usenet_client = SabnzbdDownloadClient()
log.info("SABnzbd client initialized and set as active usenet client")
except Exception as e:
log.error(f"Failed to initialize SABnzbd client: {e}")
@@ -73,10 +66,6 @@ class DownloadManager:
if self._usenet_client:
active_clients.append(f"usenet ({self._usenet_client.name})")
log.info(
f"Download manager initialized with active download clients: {', '.join(active_clients) if active_clients else 'none'}"
)
def _get_appropriate_client(
self, indexer_result: IndexerQueryResult | Torrent
) -> AbstractDownloadClient:
@@ -91,16 +80,10 @@ class DownloadManager:
if indexer_result.usenet:
if not self._usenet_client:
raise RuntimeError("No usenet download client configured")
log.info(
f"Selected usenet client: {self._usenet_client.__class__.__name__}"
)
return self._usenet_client
else:
if not self._torrent_client:
raise RuntimeError("No torrent download client configured")
log.info(
f"Selected torrent client: {self._torrent_client.__class__.__name__}"
)
return self._torrent_client
def download(self, indexer_result: IndexerQueryResult) -> Torrent:

View File

@@ -46,17 +46,13 @@ class TorrentService:
return self.torrent_repository.get_movie_of_torrent(torrent_id=torrent.id)
def download(self, indexer_result: IndexerQueryResult) -> Torrent:
log.info(f"Attempting to download torrent: {indexer_result.title}")
log.info(f"Starting download for torrent: {indexer_result.title}")
torrent = self.download_manager.download(indexer_result)
return self.torrent_repository.save_torrent(torrent=torrent)
def get_torrent_status(self, torrent: Torrent) -> Torrent:
log.info(f"Fetching status for torrent: {torrent.title}")
torrent.status = self.download_manager.get_torrent_status(torrent)
self.torrent_repository.save_torrent(torrent=torrent)
return torrent
@@ -106,6 +102,7 @@ class TorrentService:
)
def delete_torrent(self, torrent_id: TorrentId):
log.info(f"Deleting torrent with ID: {torrent_id}")
t = self.torrent_repository.get_torrent_by_id(torrent_id=torrent_id)
delete_media_files = not t.imported
self.torrent_repository.delete_torrent(