From a1dc8961eacd9f7cc6bcb9fc8983611e51cb35df Mon Sep 17 00:00:00 2001 From: Nicholas Felt Date: Wed, 12 Feb 2025 08:47:46 -0800 Subject: [PATCH] feat: Enable turning down the verbosity of failure messages during reboot of a VISA device. --- CHANGELOG.md | 4 ++++ .../driver_mixins/device_control/pi_control.py | 1 + src/tm_devices/helpers/functions.py | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a3c308e..91a8b82d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ Valid subsections within a version are: Things to be included in the next release go here. +### Added + +- Added a new parameter to the `create_visa_connection()` function which can be used to turn down the verbosity of the printouts to stdout during a reboot from `ERROR` to `DEBUG` to avoid cluttering the console with unnecessary failures while the device is still rebooting. + --- ## v3.1.1 (2025-02-04) diff --git a/src/tm_devices/driver_mixins/device_control/pi_control.py b/src/tm_devices/driver_mixins/device_control/pi_control.py index 54fa70f6..a54e5357 100644 --- a/src/tm_devices/driver_mixins/device_control/pi_control.py +++ b/src/tm_devices/driver_mixins/device_control/pi_control.py @@ -1028,6 +1028,7 @@ def _open(self) -> bool: self._visa_resource = create_visa_connection( self._config_entry, visa_library=self._visa_library_path, + verbose_connection_failure_logging=False, ) opened = True if iteration < 1 and not bool( diff --git a/src/tm_devices/helpers/functions.py b/src/tm_devices/helpers/functions.py index f40f9b0a..e53f62b1 100644 --- a/src/tm_devices/helpers/functions.py +++ b/src/tm_devices/helpers/functions.py @@ -303,6 +303,7 @@ def create_visa_connection( *, retry_connection: bool = False, second_connection_attempt_delay: int = 60, + verbose_connection_failure_logging: bool = True, ) -> MessageBasedResource: """Create a VISA resource. @@ -314,6 +315,8 @@ def create_visa_connection( between each attempt. second_connection_attempt_delay: The number of seconds to wait in between the first and second connection attempts when `retry_connection=True`. + verbose_connection_failure_logging: Indicates if the connections failures should be logged + with an ERROR level. If False, the failures will be logged with a DEBUG level. Returns: A VISA resource that can be passed into the device driver. @@ -321,6 +324,7 @@ def create_visa_connection( Raises: ConnectionError: The VISA connection couldn't be created to the device. """ + failure_logging_level = logging.ERROR if verbose_connection_failure_logging else logging.DEBUG # Set up the VISA resource that will be used for communicating with the VISA device resource_expression = device_config_entry.get_visa_resource_expression() try: @@ -351,8 +355,9 @@ def create_visa_connection( f" using the resource expression '{resource_expression}'" f" and the {repr(visa_library) if visa_library else 'default'} VISA library" ) - _logger.error(error_message) # noqa: TRY400 - _logger.error( # noqa: TRY400 + _logger.log(failure_logging_level, error_message) + _logger.log( + failure_logging_level, "1st exception: %s.%s: %s", error_1.__class__.__module__, error_1.__class__.__qualname__, @@ -379,14 +384,16 @@ def create_visa_connection( f" using the resource expression '{resource_expression}'" f" and the {repr(visa_library) if visa_library else 'default'} VISA library" ) - _logger.error(error_message) # noqa: TRY400 - _logger.error( # noqa: TRY400 + _logger.log(failure_logging_level, error_message) + _logger.log( + failure_logging_level, "1st exception: %s.%s: %s", error_1.__class__.__module__, error_1.__class__.__qualname__, error_1, ) - _logger.error( # noqa: TRY400 + _logger.log( + failure_logging_level, "2nd exception: %s.%s: %s:", error_2.__class__.__module__, error_2.__class__.__qualname__,