Skip to content

Commit 5ee2f5d

Browse files
committed
Add bind_logger helper for binding logger_name
1 parent c3cfaf3 commit 5ee2f5d

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/fastcs/attributes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
from fastcs.attribute_io_ref import AttributeIORefT
88
from fastcs.datatypes import ATTRIBUTE_TYPES, DataType, T
9-
from fastcs.logging import logger as _logger
9+
from fastcs.logging import bind_logger
1010
from fastcs.tracer import Tracer
1111

1212
ONCE = float("inf")
1313
"""Special value to indicate that an attribute should be updated once on start up."""
1414

15-
logger = _logger.bind(logger_name=__name__)
15+
logger = bind_logger(logger_name=__name__)
1616

1717

1818
class Attribute(Generic[T, AttributeIORefT], Tracer):

src/fastcs/logging/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ._graylog import GraylogStaticFields as GraylogStaticFields
88
from ._graylog import parse_graylog_env_fields as parse_graylog_env_fields
99
from ._graylog import parse_graylog_static_fields as parse_graylog_static_fields
10-
from ._logging import LogLevel, _configure_logger
10+
from ._logging import Logger, LogLevel, _configure_logger
1111

1212
logger = _logger.bind(logger_name="fastcs")
1313
"""FastCS logger
@@ -50,13 +50,25 @@
5050
fastcs. Instead there is a ``Tracer`` class for verbose logging with fine-grained
5151
controls that can be enabled by the user at runtime.
5252
53-
Use ``configure_logging`` to re-confi the logger at runtime. For more advanced
53+
Use ``configure_logging`` to re-configure the logger at runtime. For more advanced
5454
controls, configure the ``logger`` singleton directly.
5555
5656
See the ``loguru`` docs for more information: https://loguru.readthedocs.io
5757
"""
5858

5959

60+
def bind_logger(logger_name: str) -> Logger:
61+
"""Create a wrapper of the singleton fastcs logger with the given name bound
62+
63+
The name will be displayed in all log messages from the returned wrapper.
64+
65+
See the docstring for ``fastcs.logging.logger`` for more information.
66+
67+
"""
68+
69+
return logger.bind(logger_name=logger_name)
70+
71+
6072
def configure_logging(
6173
level: LogLevel | None = None,
6274
graylog_endpoint: GraylogEndpoint | None = None,

src/fastcs/transport/epics/ca/ioc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from fastcs.controller_api import ControllerAPI
1111
from fastcs.cs_methods import Command
1212
from fastcs.datatypes import DataType, T
13-
from fastcs.logging import logger as _logger
13+
from fastcs.logging import bind_logger
1414
from fastcs.tracer import Tracer
1515
from fastcs.transport.epics.ca.util import (
1616
builder_callable_from_attribute,
@@ -27,7 +27,7 @@
2727

2828

2929
tracer = Tracer(name=__name__)
30-
logger = _logger.bind(logger_name=__name__)
30+
logger = bind_logger(logger_name=__name__)
3131

3232

3333
class EpicsCAIOC:

0 commit comments

Comments
 (0)