Skip to content

Commit

Permalink
Fixes for loggers in connector and converter
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Dec 9, 2024
1 parent 08c10ff commit 4717ad8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 11 additions & 5 deletions thingsboard_gateway/connectors/bacnet/bacnet_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ def __init__(self, gateway, config, connector_type):
super().__init__()
self.__gateway = gateway
self.__config = config

self.__log = init_logger(self.__gateway, self.name, self.__config.get('logLevel', "INFO"),
enable_remote_logging=self.__config.get('enableRemoteLogging', False))
self.name = config.get('name', 'BACnet ' + ''.join(choice(ascii_lowercase) for _ in range(5)))
remote_logging = self.__config.get('enableRemoteLogging', False)
log_level = self.__config.get('logLevel', "INFO")

self.__log = init_logger(self.__gateway, self.name, log_level,
enable_remote_logging=remote_logging,
is_connector_logger=True, connector_name=self.name)
self.__converter_log = init_logger(self.__gateway, self.name, log_level,
enable_remote_logging=remote_logging,
is_converter_logger=True, connector_name=self.name)
self.__log.info('Starting BACnet connector...')

if BackwardCompatibilityAdapter.is_old_config(config):
backward_compatibility_adapter = BackwardCompatibilityAdapter(config, self.__log)
self.__config = backward_compatibility_adapter.convert()

self.__id = self.__config.get('id')
self.name = config.get('name', 'BACnet ' + ''.join(choice(ascii_lowercase) for _ in range(5)))
self.daemon = True
self.__stopped = False
self.__connected = False
Expand Down Expand Up @@ -117,7 +123,7 @@ def indication_callback(self, apdu):
if added_device is None:
device_config = Device.find_self_in_config(self.__config['devices'], apdu)
if device_config:
device = Device(self.connector_type, device_config, apdu, self.callback, self.__log)
device = Device(self.connector_type, device_config, apdu, self.callback, self.__converter_log)
self.__devices.append(device)
self.__gateway.add_device(device.device_info.device_name,
{"connector": self},
Expand Down
5 changes: 3 additions & 2 deletions thingsboard_gateway/connectors/bacnet/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
from thingsboard_gateway.connectors.bacnet.entities.uplink_converter_config import UplinkConverterConfig
from thingsboard_gateway.gateway.constants import UPLINK_PREFIX, CONVERTER_PARAMETER
from thingsboard_gateway.tb_utility.tb_loader import TBModuleLoader
from thingsboard_gateway.tb_utility.tb_logger import TbLogger


class Device(Thread):
def __init__(self, connector_type, config, i_am_request, callback, logger):
def __init__(self, connector_type, config, i_am_request, callback, logger: TbLogger):
super().__init__()

self.__connector_type = connector_type
Expand Down Expand Up @@ -75,7 +76,7 @@ def __load_uplink_converter(self):

return converter
except Exception as e:
self.__log.exception('Failed to load uplink converter for % slave: %s', self.name, e)
self.__log.exception('Failed to load uplink converter for % device: %s', self.name, e)

def stop(self):
self.active = False
Expand Down

0 comments on commit 4717ad8

Please sign in to comment.