diff --git a/laborious/activities/opc.py b/laborious/activities/opc.py index 0571709..f150bee 100644 --- a/laborious/activities/opc.py +++ b/laborious/activities/opc.py @@ -143,8 +143,8 @@ class OPC(BaseActivity): if not success: data['prediction_confidence'] = OPC_WRITTING_ERROR_CONFIDENCE self.debug( - "Some data could not be written to OPC servers, setting confidence to " - f"{OPC_WRITTING_ERROR_CONFIDENCE}." + f"Some data could not be written to OPC servers, setting confidence to {OPC_WRITTING_ERROR_CONFIDENCE}.", + metadata ) else: diff --git a/laborious/utils/repository/opc_repository.py b/laborious/utils/repository/opc_repository.py index 4685d2f..d5c0354 100644 --- a/laborious/utils/repository/opc_repository.py +++ b/laborious/utils/repository/opc_repository.py @@ -1,5 +1,4 @@ import traceback -from logging import Logger from datetime import datetime from pathlib import Path from typing import Any @@ -9,8 +8,7 @@ from asyncua.ua import DataValue, Variant, VariantType from regex import F from sientia_do.notifications.handlers import NotificationHandler from sientia_do.notifications.models import NotificationLevel - -from laborious.activities.opc import OPC +from sientia_do.temporal.utils.logger import Logger data_type_map = { 'float': { @@ -195,7 +193,7 @@ class OpcRepository(): return True def write_data(self, node: str, value: Any, data_type: str, - logger: OPC, metadata: dict[str, Any]) -> bool: + logger: Logger, metadata: dict[str, Any]) -> bool: """ Writes data to the OPC server. If the connection is not established, it attempts to reconnect. @@ -219,7 +217,7 @@ class OpcRepository(): level=NotificationLevel.ERROR, attachment_content=trace ) - logger.error(trace, metadata) + logger.custom_error(trace, metadata) self.error_count += 1 return False @@ -230,11 +228,11 @@ class OpcRepository(): block="opc_repository", level=NotificationLevel.ERROR ) - logger.error(f"Unsupported data type: {data_type}", metadata) return False data = data_type_map[data_type]['converter'](value) - logger.info(f'Writing {data} - {type(data)} to {node}', metadata) + logger.custom_info( + f'Writing {data} - {type(data)} to {node}', metadata) ua_data = DataValue( Variant(data, data_type_map[data_type]['opc_type'])) @@ -249,7 +247,7 @@ class OpcRepository(): level=NotificationLevel.ERROR, attachment_content=trace ) - logger.error(trace, metadata) + logger.custom_error(trace, metadata) self.error_count += 1 return False self.error_count = 0