From a025ae40de38176236bdb271e4f11170d014d7c4 Mon Sep 17 00:00:00 2001 From: Halali Date: Thu, 15 Nov 2018 14:39:55 +0100 Subject: [PATCH] Fix for debug logging --- bazarr/logger.py | 28 ++++++++-------------------- bazarr/main.py | 9 +++++---- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/bazarr/logger.py b/bazarr/logger.py index 1a7e34f29..daf436356 100644 --- a/bazarr/logger.py +++ b/bazarr/logger.py @@ -1,19 +1,12 @@ import os -import sys import logging import re from logging.handlers import TimedRotatingFileHandler from get_argv import config_dir -from get_settings import get_general_settings logger = logging.getLogger() -debug = get_general_settings()[4] -if debug is False: - log_level = "INFO" -else: - log_level = "DEBUG" class OneLineExceptionFormatter(logging.Formatter): def formatException(self, exc_info): @@ -39,7 +32,12 @@ class NoExceptionFormatter(logging.Formatter): return '' -def configure_logging(): +def configure_logging(debug=False): + if not debug: + log_level = "INFO" + else: + log_level = "DEBUG" + logger.handlers = [] logger.setLevel(log_level) @@ -54,7 +52,7 @@ def configure_logging(): # ch.addFilter(MyFilter()) logger.addHandler(ch) - #File Logging + # File Logging global fh fh = TimedRotatingFileHandler(os.path.join(config_dir, 'log/bazarr.log'), when="midnight", interval=1, backupCount=7) @@ -64,7 +62,7 @@ def configure_logging(): fh.addFilter(BlacklistFilter()) fh.addFilter(PublicIPFilter()) - if debug is True: + if debug: logging.getLogger("apscheduler").setLevel(logging.DEBUG) logging.getLogger("subliminal").setLevel(logging.DEBUG) logging.getLogger("git").setLevel(logging.DEBUG) @@ -145,13 +143,3 @@ class PublicIPFilter(logging.Filter): def empty_log(): fh.doRollover() - - -def update_settings(debug): - if debug == 'False': - level = "INFO" - else: - level = "DEBUG" - logger.setLevel(level) - for handler in logger.handlers: - handler.setLevel(level) diff --git a/bazarr/main.py b/bazarr/main.py index 7672c922f..4634c1b07 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -23,8 +23,9 @@ update_notifier() from get_settings import get_general_settings, get_proxy_settings import logging -from logger import configure_logging, empty_log, update_settings -configure_logging() +from logger import configure_logging, empty_log + +configure_logging(get_general_settings()[4]) import requests if get_proxy_settings()[0] != 'None': @@ -1129,8 +1130,6 @@ def save_settings(): cfg.set('general', 'use_embedded_subs', text_type(settings_general_embedded)) cfg.set('general', 'only_monitored', text_type(settings_general_only_monitored)) cfg.set('general', 'adaptive_searching', text_type(settings_general_adaptive_searching)) - - update_settings(settings_general_debug) if after != before: configured() @@ -1301,6 +1300,8 @@ def save_settings(): with open(config_file, 'wb') as f: cfg.write(f) + configure_logging(get_general_settings()[4]) + notifiers = c.execute("SELECT * FROM table_settings_notifier ORDER BY name").fetchall() for notifier in notifiers: enabled = request.forms.get('settings_notifier_' + notifier[0] + '_enabled')