From b5025141ae982b748d50cc0563c8b167d8bb3790 Mon Sep 17 00:00:00 2001 From: zbeacon Date: Mon, 24 Feb 2020 11:10:37 +0200 Subject: [PATCH] Improvements for remote logging --- .../gateway/tb_gateway_remote_configurator.py | 8 +++++--- thingsboard_gateway/gateway/tb_gateway_service.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/thingsboard_gateway/gateway/tb_gateway_remote_configurator.py b/thingsboard_gateway/gateway/tb_gateway_remote_configurator.py index 1409bbe0..0ae45a5f 100644 --- a/thingsboard_gateway/gateway/tb_gateway_remote_configurator.py +++ b/thingsboard_gateway/gateway/tb_gateway_remote_configurator.py @@ -109,6 +109,7 @@ class RemoteConfigurator: self.__new_connectors_configs = {} self.__old_general_configuration_file = self.__new_general_configuration_file self.__old_logs_configuration = self.__new_logs_configuration + self.__update_logs_configuration() self.__new_logs_configuration = None self.__new_general_configuration_file = {} return True @@ -256,9 +257,10 @@ class RemoteConfigurator: new_logging_level = findall(r'level=(.*)', self.__new_logs_configuration.replace("NONE", "NOTSET"))[-1] with open(logs_conf_file_path, 'w') as logs: logs.write(self.__new_logs_configuration.replace("NONE", "NOTSET")+"\r\n") - fileConfig(logs_conf_file_path) - self.__gateway.main_handler = MemoryHandler(-1) - self.__gateway.remote_handler = TBLoggerHandler(self.__gateway) + # fileConfig(logs_conf_file_path) + # self.__gateway.main_handler = MemoryHandler(-1) + self.__gateway.main_handler.setLevel(new_logging_level) + # self.__gateway.remote_handler = TBLoggerHandler(self.__gateway) self.__gateway.main_handler.setTarget(self.__gateway.remote_handler) if new_logging_level == "NOTSET": self.__gateway.remote_handler.deactivate() diff --git a/thingsboard_gateway/gateway/tb_gateway_service.py b/thingsboard_gateway/gateway/tb_gateway_service.py index c11d47f6..66c5ad01 100644 --- a/thingsboard_gateway/gateway/tb_gateway_service.py +++ b/thingsboard_gateway/gateway/tb_gateway_service.py @@ -57,6 +57,7 @@ class TBGatewayService: self.tb_client = TBClient(config["thingsboard"]) self.tb_client.connect() self.subscribe_to_required_topics() + self.counter = 0 global main_handler self.main_handler = main_handler self.remote_handler = TBLoggerHandler(self) @@ -275,6 +276,7 @@ class TBGatewayService: events = self._event_storage.get_event_pack() if events: for event in events: + self.counter += 1 try: current_event = loads(event) except Exception as e: @@ -315,7 +317,7 @@ class TBGatewayService: while not self._published_events.empty(): if self.__remote_configurator.in_process or not self.tb_client.is_connected() or self._published_events.empty(): break - event = self._published_events.get(True, 10) + event = self._published_events.get(False, 10) try: if self.tb_client.is_connected() and (self.__remote_configurator is None or not self.__remote_configurator.in_process): success = event.get() == event.TB_ERR_SUCCESS