SIENTIAPDE-1110
Refactor logging in OPC and OpcRepository to utilize custom logging methods, enhancing error handling and traceability with metadata integration.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user