Skip to content

Commit

Permalink
use ophyd async logger for logging.debug statements (#686)
Browse files Browse the repository at this point in the history
* use ophyd async logger for logging.debug statements

* fix the logging.exception in _utils.py, add LOG015 and ruff docs link to linting rules, add noqa to make_switcher.py
  • Loading branch information
rerpha authored Jan 14, 2025
1 parent 4658c48 commit caa0f5c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/pages/make_switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_versions(ref: str, add: str | None) -> list[str]:
builds = set(get_branch_contents(ref))
except CalledProcessError:
builds = set()
logging.warning(f"Cannot get {ref} contents")
logging.warning(f"Cannot get {ref} contents") # noqa: LOG015

# Add and remove from the list of builds
if add:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ lint.select = [
"UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up
"SLF", # self - https://docs.astral.sh/ruff/settings/#lintflake8-self
"PLC2701", # private import - https://docs.astral.sh/ruff/rules/import-private-name/
"LOG015", # root logger call - https://docs.astral.sh/ruff/rules/root-logger-call/
]
lint.ignore = [
"B901", # Return in a generator is needed for plans
Expand Down
4 changes: 3 additions & 1 deletion src/ophyd_async/core/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
DEFAULT_TIMEOUT = 10.0
ErrorText = str | Mapping[str, Exception]

logger = logging.getLogger("ophyd_async")


class StrictEnumMeta(EnumMeta):
def __new__(metacls, *args, **kwargs):
Expand Down Expand Up @@ -114,7 +116,7 @@ def with_other_exceptions_logged(
) -> NotConnected:
for name, exception in exceptions.items():
if not isinstance(exception, NotConnected):
logging.exception(
logger.exception(
f"device `{name}` raised unexpected exception "
f"{type(exception).__name__}",
exc_info=exception,
Expand Down
4 changes: 3 additions & 1 deletion src/ophyd_async/epics/core/_aioca.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

from ._util import EpicsSignalBackend, format_datatype, get_supported_values

logger = logging.getLogger("ophyd_async")


def _limits_from_augmented_value(value: AugmentedValue) -> Limits:
def get_limits(limit: str) -> LimitsRange | None:
Expand Down Expand Up @@ -258,7 +260,7 @@ async def _store_initial_value(self, pv: str, timeout: float):
pv, format=FORMAT_CTRL, timeout=timeout
)
except CANothing as exc:
logging.debug(f"signal ca://{pv} timed out")
logger.debug(f"signal ca://{pv} timed out")
raise NotConnected(f"ca://{pv}") from exc

async def connect(self, timeout: float):
Expand Down
4 changes: 3 additions & 1 deletion src/ophyd_async/epics/core/_p4p.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

from ._util import EpicsSignalBackend, format_datatype, get_supported_values

logger = logging.getLogger("ophyd_async")


def _limits_from_value(value: Any) -> Limits:
def get_limits(
Expand Down Expand Up @@ -321,7 +323,7 @@ async def pvget_with_timeout(pv: str, timeout: float) -> Any:
try:
return await asyncio.wait_for(context().get(pv), timeout=timeout)
except asyncio.TimeoutError as exc:
logging.debug(f"signal pva://{pv} timed out", exc_info=True)
logger.debug(f"signal pva://{pv} timed out", exc_info=True)
raise NotConnected(f"pva://{pv}") from exc


Expand Down
4 changes: 3 additions & 1 deletion src/ophyd_async/tango/core/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

from ._tango_transport import TangoSignalBackend, get_python_type

logger = logging.getLogger("ophyd_async")


def make_backend(
datatype: type[SignalDatatypeT] | None,
Expand Down Expand Up @@ -205,7 +207,7 @@ async def infer_signal_type(
if config.in_type == CmdArgType.DevVoid:
return SignalX
elif config.in_type != config.out_type:
logging.debug("Commands with different in and out dtypes are not supported")
logger.debug("Commands with different in and out dtypes are not supported")
return None
else:
return SignalRW
Expand Down

0 comments on commit caa0f5c

Please sign in to comment.