mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-14 09:12:58 -07:00
Disable logging while library update in progress
This commit is contained in:
parent
4e0f06f24d
commit
5faf357045
2 changed files with 26 additions and 3 deletions
|
@ -18,6 +18,7 @@ import plexpy
|
|||
|
||||
def update_section_ids():
|
||||
from plexpy import pmsconnect, activity_pinger
|
||||
import threading
|
||||
|
||||
plexpy.CONFIG.UPDATE_SECTION_IDS = -1
|
||||
|
||||
|
@ -39,7 +40,7 @@ def update_section_ids():
|
|||
except Exception as e:
|
||||
logger.warn(u"PlexPy Libraries :: Unable to execute database query for update_section_ids: %s." % e)
|
||||
|
||||
logger.debug(u"PlexPy Libraries :: Unable to update section_id's in database.")
|
||||
logger.warn(u"PlexPy Libraries :: Unable to update section_id's in database.")
|
||||
plexpy.CONFIG.__setattr__('UPDATE_SECTION_IDS', 1)
|
||||
plexpy.CONFIG.write()
|
||||
|
||||
|
@ -47,6 +48,12 @@ def update_section_ids():
|
|||
plexpy.initialize_scheduler()
|
||||
return None
|
||||
|
||||
# Add thread filter to the logger
|
||||
logger.debug(u"PlexPy Libraries :: Disabling logging in the current thread while update in progress.")
|
||||
thread_filter = logger.NoThreadFilter(threading.current_thread().name)
|
||||
for handler in logger.logger.handlers:
|
||||
handler.addFilter(thread_filter)
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
|
||||
error_keys = set()
|
||||
|
@ -63,11 +70,16 @@ def update_section_ids():
|
|||
else:
|
||||
error_keys.add(rating_key)
|
||||
|
||||
# Remove thread filter from the logger
|
||||
for handler in logger.logger.handlers:
|
||||
handler.removeFilter(thread_filter)
|
||||
logger.debug(u"PlexPy Libraries :: Re-enabling logging in the current thread.")
|
||||
|
||||
if error_keys:
|
||||
logger.debug(u"PlexPy Libraries :: Updated all section_id's in database except for rating_keys: %s." %
|
||||
logger.info(u"PlexPy Libraries :: Updated all section_id's in database except for rating_keys: %s." %
|
||||
', '.join(str(key) for key in error_keys))
|
||||
else:
|
||||
logger.debug(u"PlexPy Libraries :: Updated all section_id's in database.")
|
||||
logger.info(u"PlexPy Libraries :: Updated all section_id's in database.")
|
||||
|
||||
plexpy.CONFIG.__setattr__('UPDATE_SECTION_IDS', 0)
|
||||
plexpy.CONFIG.write()
|
||||
|
|
|
@ -51,6 +51,17 @@ class LogListHandler(logging.Handler):
|
|||
plexpy.LOG_LIST.insert(0, (helpers.now(), message, record.levelname, record.threadName))
|
||||
|
||||
|
||||
class NoThreadFilter(logging.Filter):
|
||||
"""
|
||||
Log filter for the current thread
|
||||
"""
|
||||
def __init__(self, threadName):
|
||||
self.threadName = threadName
|
||||
|
||||
def filter(self, record):
|
||||
return not record.threadName == self.threadName
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def listener():
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue