Skip to content

Commit

Permalink
use the right logger in tcpip sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuDartiailh committed Sep 18, 2024
1 parent aca46b3 commit 79a39c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
5 changes: 0 additions & 5 deletions pyvisa_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
"""

import logging
from importlib.metadata import PackageNotFoundError, version

# we need to import so that __init_subclass__() is executed once (hence the noqa)
from . import attributes # noqa: F401
from .highlevel import PyVisaLibrary

# Global pyvisa-py logger used to provide more details on errors (VISA error code
# can make some report rather terse).
LOGGER = logging.getLogger("pyvisa.pyvisa-py")

__version__ = "unknown"
try:
__version__ = version(__name__)
Expand Down
10 changes: 5 additions & 5 deletions pyvisa_py/tcpip.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pyvisa import attributes, constants, errors, rname
from pyvisa.constants import BufferOperation, ResourceAttribute, StatusCode

from . import LOGGER, common
from . import common
from .protocols import hislip, rpc, vxi11
from .sessions import OpenError, Session, UnknownAttribute, VISARMSession

Expand Down Expand Up @@ -149,7 +149,7 @@ def after_parsing(self) -> None:
sub_address=sub_address,
)
except OSError as e:
LOGGER.exception(
common.logger.exception(

Check warning on line 152 in pyvisa_py/tcpip.py

View check run for this annotation

Codecov / codecov/patch

pyvisa_py/tcpip.py#L151-L152

Added lines #L151 - L152 were not covered by tests
f"Failed to open HiSLIP connection to {self.parsed.host_address} "
f"on port {port} with lan device name {sub_address}"
)
Expand Down Expand Up @@ -490,7 +490,7 @@ def after_parsing(self) -> None:
try:
self.interface = Vxi11CoreClient(host_address, port, self.open_timeout)
except rpc.RPCError:
LOGGER.exception(
common.logger.exception(

Check warning on line 493 in pyvisa_py/tcpip.py

View check run for this annotation

Codecov / codecov/patch

pyvisa_py/tcpip.py#L493

Added line #L493 was not covered by tests
f"Failed to open VX11 connection to {host_address} on port {port}"
)
raise OpenError()

Check warning on line 496 in pyvisa_py/tcpip.py

View check run for this annotation

Codecov / codecov/patch

pyvisa_py/tcpip.py#L496

Added line #L496 was not covered by tests
Expand Down Expand Up @@ -522,7 +522,7 @@ def close(self) -> StatusCode:
try:
self.interface.destroy_link(self.link)
except (errors.VisaIOError, socket.error, rpc.RPCError) as e:
LOGGER.error("Error closing VISA link: {}".format(e))
common.logger.error("Error closing VISA link: {}".format(e))

Check warning on line 525 in pyvisa_py/tcpip.py

View check run for this annotation

Codecov / codecov/patch

pyvisa_py/tcpip.py#L525

Added line #L525 was not covered by tests

self.interface.close()
self.link = 0
Expand Down Expand Up @@ -886,7 +886,7 @@ def after_parsing(self) -> None:
self.parsed.host_address, port, timeout=self.timeout
)
except OSError as e:
LOGGER.exception(
common.logger.exception(

Check warning on line 889 in pyvisa_py/tcpip.py

View check run for this annotation

Codecov / codecov/patch

pyvisa_py/tcpip.py#L888-L889

Added lines #L888 - L889 were not covered by tests
f"Failed to open VICP connection to {self.parsed.host_address} "
f"on port {port}"
)
Expand Down

0 comments on commit 79a39c5

Please sign in to comment.