Skip to content

Commit

Permalink
Merge pull request #379 from gudvinr/feature/372_reduce-logging-chatter
Browse files Browse the repository at this point in the history
make shim logger configurable
  • Loading branch information
iwalton3 authored May 13, 2024
2 parents e2d7daf + 221f875 commit 0e8b3db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 1 addition & 2 deletions jellyfin_mpv_shim/gui_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .conffile import confdir
from .clients import clientManager
from .utils import get_resource
from .log_utils import CustomFormatter
from .log_utils import CustomFormatter, root_logger
from .i18n import _

log = logging.getLogger("gui_mgr")
Expand Down Expand Up @@ -52,7 +52,6 @@ def open_config():

# Setup a log handler for log items.
log_cache = deque([], 1000)
root_logger = logging.getLogger("")


class GUILogHandler(logging.Handler):
Expand Down
12 changes: 9 additions & 3 deletions jellyfin_mpv_shim/log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

sanitize_logs = False
root_logger = logging.getLogger("")
root_logger.level = logging.DEBUG
root_logger.level = logging.INFO


def sanitize(message):
Expand Down Expand Up @@ -52,14 +52,20 @@ def enable_sanitization():
sanitize_logs = True


def configure_log(destination):
def configure_log(destination, level: str="info"):
lvl = logging.getLevelNamesMapping()[level.upper()]

handler = logging.StreamHandler(destination)
handler.setFormatter(CustomFormatter())
handler.setLevel(lvl)
root_logger.addHandler(handler)


def configure_log_file(destination: str):
def configure_log_file(destination: str, level: str="info"):
lvl = logging.getLevelNamesMapping()[level.upper()]

handler = logging.FileHandler(destination, mode="w")
# Never allow logging API keys to a file.
handler.setFormatter(CustomFormatter(True))
handler.setLevel(lvl)
root_logger.addHandler(handler)
9 changes: 5 additions & 4 deletions jellyfin_mpv_shim/mpv_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
from .conf import settings
from .clients import clientManager
from .constants import APP_NAME
from .log_utils import configure_log, enable_sanitization, configure_log_file
from .log_utils import configure_log, configure_log_file, enable_sanitization, root_logger

configure_log(sys.stdout)
log = logging.getLogger("")
logging.getLogger("requests").setLevel(logging.CRITICAL)


Expand All @@ -25,9 +23,12 @@ def main():
if settings.sanitize_output:
enable_sanitization()

configure_log(sys.stdout, settings.mpv_log_level)
if settings.write_logs:
log_file = conffile.get(APP_NAME, "log.txt")
configure_log_file(log_file)
configure_log_file(log_file, settings.mpv_log_level)

log = root_logger

if sys.platform.startswith("darwin"):
multiprocessing.set_start_method("forkserver")
Expand Down

0 comments on commit 0e8b3db

Please sign in to comment.