mirror of
https://github.com/thingsboard/thingsboard-gateway
synced 2025-10-26 22:31:42 +08:00
Improvements for remote logging
This commit is contained in:
@@ -109,6 +109,7 @@ class RemoteConfigurator:
|
|||||||
self.__new_connectors_configs = {}
|
self.__new_connectors_configs = {}
|
||||||
self.__old_general_configuration_file = self.__new_general_configuration_file
|
self.__old_general_configuration_file = self.__new_general_configuration_file
|
||||||
self.__old_logs_configuration = self.__new_logs_configuration
|
self.__old_logs_configuration = self.__new_logs_configuration
|
||||||
|
self.__update_logs_configuration()
|
||||||
self.__new_logs_configuration = None
|
self.__new_logs_configuration = None
|
||||||
self.__new_general_configuration_file = {}
|
self.__new_general_configuration_file = {}
|
||||||
return True
|
return True
|
||||||
@@ -256,9 +257,10 @@ class RemoteConfigurator:
|
|||||||
new_logging_level = findall(r'level=(.*)', self.__new_logs_configuration.replace("NONE", "NOTSET"))[-1]
|
new_logging_level = findall(r'level=(.*)', self.__new_logs_configuration.replace("NONE", "NOTSET"))[-1]
|
||||||
with open(logs_conf_file_path, 'w') as logs:
|
with open(logs_conf_file_path, 'w') as logs:
|
||||||
logs.write(self.__new_logs_configuration.replace("NONE", "NOTSET")+"\r\n")
|
logs.write(self.__new_logs_configuration.replace("NONE", "NOTSET")+"\r\n")
|
||||||
fileConfig(logs_conf_file_path)
|
# fileConfig(logs_conf_file_path)
|
||||||
self.__gateway.main_handler = MemoryHandler(-1)
|
# self.__gateway.main_handler = MemoryHandler(-1)
|
||||||
self.__gateway.remote_handler = TBLoggerHandler(self.__gateway)
|
self.__gateway.main_handler.setLevel(new_logging_level)
|
||||||
|
# self.__gateway.remote_handler = TBLoggerHandler(self.__gateway)
|
||||||
self.__gateway.main_handler.setTarget(self.__gateway.remote_handler)
|
self.__gateway.main_handler.setTarget(self.__gateway.remote_handler)
|
||||||
if new_logging_level == "NOTSET":
|
if new_logging_level == "NOTSET":
|
||||||
self.__gateway.remote_handler.deactivate()
|
self.__gateway.remote_handler.deactivate()
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class TBGatewayService:
|
|||||||
self.tb_client = TBClient(config["thingsboard"])
|
self.tb_client = TBClient(config["thingsboard"])
|
||||||
self.tb_client.connect()
|
self.tb_client.connect()
|
||||||
self.subscribe_to_required_topics()
|
self.subscribe_to_required_topics()
|
||||||
|
self.counter = 0
|
||||||
global main_handler
|
global main_handler
|
||||||
self.main_handler = main_handler
|
self.main_handler = main_handler
|
||||||
self.remote_handler = TBLoggerHandler(self)
|
self.remote_handler = TBLoggerHandler(self)
|
||||||
@@ -275,6 +276,7 @@ class TBGatewayService:
|
|||||||
events = self._event_storage.get_event_pack()
|
events = self._event_storage.get_event_pack()
|
||||||
if events:
|
if events:
|
||||||
for event in events:
|
for event in events:
|
||||||
|
self.counter += 1
|
||||||
try:
|
try:
|
||||||
current_event = loads(event)
|
current_event = loads(event)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -315,7 +317,7 @@ class TBGatewayService:
|
|||||||
while not self._published_events.empty():
|
while not self._published_events.empty():
|
||||||
if self.__remote_configurator.in_process or not self.tb_client.is_connected() or self._published_events.empty():
|
if self.__remote_configurator.in_process or not self.tb_client.is_connected() or self._published_events.empty():
|
||||||
break
|
break
|
||||||
event = self._published_events.get(True, 10)
|
event = self._published_events.get(False, 10)
|
||||||
try:
|
try:
|
||||||
if self.tb_client.is_connected() and (self.__remote_configurator is None or not self.__remote_configurator.in_process):
|
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
|
success = event.get() == event.TB_ERR_SUCCESS
|
||||||
|
|||||||
Reference in New Issue
Block a user