Skip to content

Commit

Permalink
Merge pull request #229 from luigi311/loguru
Browse files Browse the repository at this point in the history
Switch logging to loguru
  • Loading branch information
luigi311 authored Feb 21, 2025
2 parents 8f4a2e2 + 588c23c commit 305fea8
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 200 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description = "Sync watched between media servers locally"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"loguru>=0.7.3",
"packaging==24.2",
"plexapi==4.16.1",
"pydantic==2.10.6",
Expand Down
10 changes: 6 additions & 4 deletions src/black_white.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from src.functions import logger, search_mapping
from loguru import logger

from src.functions import search_mapping


def setup_black_white_lists(
Expand Down Expand Up @@ -58,13 +60,13 @@ def setup_x_lists(
temp_library.append(library_other)

out_library = out_library + temp_library
logger(f"{xlist_type}list Library: {xlist_library}", 1)
logger.info(f"{xlist_type}list Library: {xlist_library}")

out_library_type: list[str] = []
if xlist_library_type:
out_library_type = [x.lower().strip() for x in xlist_library_type]

logger(f"{xlist_type}list Library Type: {out_library_type}", 1)
logger.info(f"{xlist_type}list Library Type: {out_library_type}")

out_users: list[str] = []
if xlist_users:
Expand All @@ -78,6 +80,6 @@ def setup_x_lists(

out_users = out_users + temp_users

logger(f"{xlist_type}list Users: {out_users}", 1)
logger.info(f"{xlist_type}list Users: {out_users}")

return out_library, out_library_type, out_users
9 changes: 5 additions & 4 deletions src/connection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
from typing import Literal
from dotenv import load_dotenv
from loguru import logger

from src.functions import logger, str_to_bool
from src.functions import str_to_bool
from src.plex import Plex
from src.jellyfin import Jellyfin
from src.emby import Emby
Expand Down Expand Up @@ -39,7 +40,7 @@ def jellyfin_emby_server_connection(
else:
raise Exception("Unknown server type")

logger(f"{server_type} Server {i} info: {server.info()}", 3)
logger.debug(f"{server_type} Server {i} info: {server.info()}")

return servers

Expand Down Expand Up @@ -73,7 +74,7 @@ def generate_server_connections() -> list[Plex | Jellyfin | Emby]:
ssl_bypass=ssl_bypass,
)

logger(f"Plex Server {i} info: {server.info()}", 3)
logger.debug(f"Plex Server {i} info: {server.info()}")

servers.append(server)

Expand All @@ -99,7 +100,7 @@ def generate_server_connections() -> list[Plex | Jellyfin | Emby]:
ssl_bypass=ssl_bypass,
)

logger(f"Plex Server {i} info: {server.info()}", 3)
logger.debug(f"Plex Server {i} info: {server.info()}")
servers.append(server)

jellyfin_baseurl = os.getenv("JELLYFIN_BASEURL", None)
Expand Down
28 changes: 0 additions & 28 deletions src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,6 @@
mark_file = os.getenv("MARK_FILE", os.getenv("MARKFILE", "mark.log"))


def logger(message: str, log_type: int = 0):
debug = str_to_bool(os.getenv("DEBUG", "False"))
debug_level = os.getenv("DEBUG_LEVEL", "info").lower()

output: str | None = str(message)
if log_type == 0:
pass
elif log_type == 1 and (debug and debug_level in ("info", "debug")):
output = f"[INFO]: {output}"
elif log_type == 2:
output = f"[ERROR]: {output}"
elif log_type == 3 and (debug and debug_level == "debug"):
output = f"[DEBUG]: {output}"
elif log_type == 4:
output = f"[WARNING]: {output}"
elif log_type == 5:
output = f"[MARK]: {output}"
elif log_type == 6:
output = f"[DRYRUN]: {output}"
else:
output = None

if output is not None:
print(output)
with open(f"{log_file}", "a", encoding="utf-8") as file:
file.write(output + "\n")


def log_marked(
server_type: str,
server_name: str,
Expand Down
Loading

0 comments on commit 305fea8

Please sign in to comment.