Skip to content

Commit

Permalink
Added file handlers updating method
Browse files Browse the repository at this point in the history
  • Loading branch information
samson0v committed Dec 16, 2024
1 parent b5f5e24 commit 4604d8f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions thingsboard_gateway/gateway/tb_gateway_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from thingsboard_gateway.tb_utility.tb_loader import TBModuleLoader
from thingsboard_gateway.tb_utility.tb_logger import TbLogger
from thingsboard_gateway.tb_utility.tb_remote_shell import RemoteShell
from thingsboard_gateway.tb_utility.tb_rotating_file_handler import TimedRotatingFileHandler
from thingsboard_gateway.tb_utility.tb_updater import TBUpdater
from thingsboard_gateway.tb_utility.tb_utility import TBUtility

Expand Down Expand Up @@ -2065,6 +2066,7 @@ def get_status(self):

def update_loggers(self):
self.__update_base_loggers()
self.__update_connectors_and_converters_loggers()

global log
log = logging.getLogger('service')
Expand All @@ -2081,6 +2083,25 @@ def __update_base_loggers(self):

logger.addHandler(self.remote_handler)

def __update_connectors_and_converters_loggers(self):
for logger in logging.Logger.manager.loggerDict.values():
if hasattr(logger, 'is_connector_logger') or hasattr(logger, 'is_converter_logger'):
file_handler_filter = list(filter(lambda handler: isinstance(handler, TimedRotatingFileHandler),
logger.handlers))
if len(file_handler_filter):
old_file_handler = file_handler_filter[0]

new_file_handler = None
if logger.is_connector_logger:
new_file_handler = TimedRotatingFileHandler.get_connector_file_handler(old_file_handler.baseFilename.split('/')[-1]) # noqa

if logger.is_converter_logger:
new_file_handler = TimedRotatingFileHandler.get_converter_file_handler(old_file_handler.baseFilename.split('/')[-1]) # noqa

if new_file_handler:
logger.addHandler(new_file_handler)
logger.removeHandler(old_file_handler)

def is_latency_metrics_enabled(self):
return self.__latency_debug_mode

Expand Down

0 comments on commit 4604d8f

Please sign in to comment.