mirror of
https://github.com/thingsboard/thingsboard-gateway
synced 2025-10-26 22:31:42 +08:00
Improvements for Remote Logging and OPC-UA
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
log = logging.getLogger("tb_gateway.connector")
|
||||
log = logging.getLogger("connector")
|
||||
|
||||
|
||||
class Connector(ABC):
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
log = logging.getLogger("tb_gateway.converter")
|
||||
log = logging.getLogger("converter")
|
||||
|
||||
|
||||
class Converter(ABC):
|
||||
|
||||
@@ -105,8 +105,11 @@ class OpcUaConnector(Thread, Connector):
|
||||
self.__opcua_nodes["root"] = self.client.get_root_node()
|
||||
self.__opcua_nodes["objects"] = self.client.get_objects_node()
|
||||
sub = self.client.create_subscription(self.__server_conf.get("scanPeriodInMillis", 500), self.__sub_handler)
|
||||
self.__search_name(self.__opcua_nodes["objects"], 2)
|
||||
self.__search_tags(self.__opcua_nodes["objects"], 2, sub)
|
||||
# self.__search_name(self.__opcua_nodes["objects"], 2)
|
||||
# self.__search_tags(self.__opcua_nodes["objects"], 2, sub)
|
||||
|
||||
self.__search_name(self.__opcua_nodes["root"], 0)
|
||||
self.__search_tags(self.__opcua_nodes["root"], 0, sub)
|
||||
log.debug('Subscriptions: %s', self.subscribed)
|
||||
|
||||
log.debug("Available methods: %s", self.__available_object_resources)
|
||||
|
||||
@@ -17,7 +17,7 @@ import time
|
||||
from thingsboard_gateway.tb_client.tb_gateway_mqtt import TBGatewayMqttClient
|
||||
import threading
|
||||
|
||||
log = logging.getLogger("tb_gateway.tb_connection")
|
||||
log = logging.getLogger("tb_connection")
|
||||
|
||||
|
||||
class TBClient(threading.Thread):
|
||||
|
||||
@@ -21,7 +21,7 @@ from os import remove
|
||||
from thingsboard_gateway.gateway.tb_client import TBClient
|
||||
from thingsboard_gateway.gateway.tb_logger import TBLoggerHandler
|
||||
|
||||
log = getLogger("tb_gateway.service")
|
||||
log = getLogger("service")
|
||||
|
||||
|
||||
class RemoteConfigurator:
|
||||
|
||||
@@ -31,7 +31,7 @@ from thingsboard_gateway.storage.memory_event_storage import MemoryEventStorage
|
||||
from thingsboard_gateway.storage.file_event_storage import FileEventStorage
|
||||
from thingsboard_gateway.gateway.tb_gateway_remote_configurator import RemoteConfigurator
|
||||
|
||||
log = logging.getLogger('tb_gateway.service')
|
||||
log = logging.getLogger('service')
|
||||
main_handler = logging.handlers.MemoryHandler(-1)
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ class TBGatewayService:
|
||||
config = safe_load(config)
|
||||
self._config_dir = path.dirname(path.abspath(config_file)) + '/'
|
||||
logging.config.fileConfig(self._config_dir + "logs.conf")
|
||||
# global log
|
||||
# log = logging.getLogger('tb_gateway.service')
|
||||
global log
|
||||
log = logging.getLogger('service')
|
||||
self.available_connectors = {}
|
||||
self.__connector_incoming_messages = {}
|
||||
self.__connected_devices = {}
|
||||
@@ -132,6 +132,7 @@ class TBGatewayService:
|
||||
str(connector_camel_case + ' EventsSent').replace(' ', '')]
|
||||
self.tb_client.client.send_telemetry(summary_messages)
|
||||
gateway_statistic_send = time.time()
|
||||
self.__check_shared_attributes()
|
||||
except KeyboardInterrupt as e:
|
||||
log.info("Stopping...")
|
||||
self.__close_connectors()
|
||||
@@ -170,11 +171,14 @@ class TBGatewayService:
|
||||
self.__remote_configurator.process_configuration(content.get("configuration"))
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
if (shared_attributes is not None and shared_attributes.get('RemoteLoggingLevel') == 'NONE') or content.get("RemoteLoggingLevel") == 'NONE':
|
||||
remote_logging_level = shared_attributes.get('RemoteLoggingLevel', content.get("RemoteLoggingLevel"))
|
||||
if remote_logging_level == 'NONE':
|
||||
self.remote_handler.deactivate()
|
||||
log.info('Remote logging has being deactivated.')
|
||||
elif (shared_attributes is not None and shared_attributes.get('RemoteLoggingLevel') is not None) or content.get("RemoteLoggingLevel") is not None:
|
||||
self.remote_handler.activate(content.get('RemoteLoggingLevel'))
|
||||
elif remote_logging_level is not None:
|
||||
if self.remote_handler.current_log_level != remote_logging_level:
|
||||
self.remote_handler.activate(remote_logging_level)
|
||||
if not self.remote_handler.activated:
|
||||
log.info('Remote logging has being activated.')
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
|
||||
@@ -20,14 +20,15 @@ from time import time
|
||||
|
||||
class TBLoggerHandler(logging.Handler):
|
||||
def __init__(self, gateway):
|
||||
self.__current_log_level = 'DEBUG'
|
||||
self.current_log_level = 'NONE'
|
||||
super().__init__(logging.getLevelName(self.__current_log_level))
|
||||
self.__gateway = gateway
|
||||
self.activated = False
|
||||
self.loggers = ['tb_gateway.service',
|
||||
'tb_gateway.storage',
|
||||
'tb_gateway.extension',
|
||||
'tb_gateway.connector'
|
||||
self.loggers = ['service',
|
||||
'storage',
|
||||
'extension',
|
||||
'connector',
|
||||
'tb_connection'
|
||||
]
|
||||
for logger in self.loggers:
|
||||
log = logging.getLogger(logger)
|
||||
@@ -38,12 +39,15 @@ class TBLoggerHandler(logging.Handler):
|
||||
try:
|
||||
for logger in self.loggers:
|
||||
if log_level is not None and logging.getLevelName(log_level) is not None:
|
||||
if logger == 'tb_connection' and log_level == 'DEBUG':
|
||||
log = logging.getLogger(logger)
|
||||
log.setLevel(logging.getLevelName('INFO'))
|
||||
else:
|
||||
log = logging.getLogger(logger)
|
||||
# log.addHandler(self)
|
||||
self.__current_log_level = log_level
|
||||
log.setLevel(logging.getLevelName(log_level))
|
||||
except Exception as e:
|
||||
log = logging.getLogger('tb_gateway.service')
|
||||
log = logging.getLogger('service')
|
||||
log.exception(e)
|
||||
self.activated = True
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
from logging import getLogger
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
log = getLogger("tb_gateway.storage")
|
||||
log = getLogger("storage")
|
||||
|
||||
class EventStorage(ABC):
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ ATTRIBUTES_TOPIC = 'v1/devices/me/attributes'
|
||||
ATTRIBUTES_TOPIC_REQUEST = 'v1/devices/me/attributes/request/'
|
||||
ATTRIBUTES_TOPIC_RESPONSE = 'v1/devices/me/attributes/response/'
|
||||
TELEMETRY_TOPIC = 'v1/devices/me/telemetry'
|
||||
log = logging.getLogger("tb_gateway.tb_connection")
|
||||
log = logging.getLogger("tb_connection")
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ GATEWAY_ATTRIBUTES_RESPONSE_TOPIC = "v1/gateway/attributes/response"
|
||||
GATEWAY_MAIN_TOPIC = "v1/gateway/"
|
||||
GATEWAY_RPC_TOPIC = "v1/gateway/rpc"
|
||||
|
||||
log = logging.getLogger("tb_gateway.tb_connection")
|
||||
log = logging.getLogger("tb_connection")
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user