Fix inotify event logs triggering themselves (infinite log recursion)

This commit is contained in:
Kristóf Tóth 2018-05-29 10:55:55 +02:00
parent 029f4a9eb2
commit 32e3c2860d

View File

@ -1,6 +1,7 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft. # Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details. # All Rights Reserved. See LICENSE file for details.
import logging
from os.path import dirname from os.path import dirname
from watchdog.events import PatternMatchingEventHandler as PatternMatchingWatchdogEventHandler from watchdog.events import PatternMatchingEventHandler as PatternMatchingWatchdogEventHandler
@ -12,6 +13,7 @@ from tfw.mixins import ObserverMixin, SupervisorLogMixin
class LogMonitor(ObserverMixin): class LogMonitor(ObserverMixin):
def __init__(self, process_name): def __init__(self, process_name):
self.prevent_log_recursion()
ObserverMixin.__init__(self) ObserverMixin.__init__(self)
event_handler = SendLogWatchdogEventHandler(process_name) event_handler = SendLogWatchdogEventHandler(process_name)
self.observer.schedule( self.observer.schedule(
@ -19,6 +21,11 @@ class LogMonitor(ObserverMixin):
event_handler.path event_handler.path
) )
@staticmethod
def prevent_log_recursion():
# This is done to prevent inotify event logs triggering themselves (infinite log recursion)
logging.getLogger('watchdog.observers.inotify_buffer').propagate = False
class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin): class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin):
def __init__(self, process_name): def __init__(self, process_name):