|
15 | 15 |
|
16 | 16 | from fastcs import __version__ |
17 | 17 | from fastcs.attribute_io_ref import AttributeIORef |
| 18 | +from fastcs.logging import ( |
| 19 | + GraylogEndpoint, |
| 20 | + GraylogEnvFields, |
| 21 | + GraylogStaticFields, |
| 22 | + LogLevel, |
| 23 | + configure_logging, |
| 24 | + parse_graylog_env_fields, |
| 25 | + parse_graylog_static_fields, |
| 26 | +) |
| 27 | +from fastcs.logging import logger as _fastcs_logger |
| 28 | +from fastcs.tracer import Tracer |
18 | 29 | from fastcs.transport.epics.ca.transport import EpicsCATransport |
19 | 30 | from fastcs.transport.epics.pva.transport import EpicsPVATransport |
20 | 31 | from fastcs.transport.graphql.transport import GraphQLTransport |
|
39 | 50 | | GraphQLTransport |
40 | 51 | ] |
41 | 52 |
|
| 53 | +tracer = Tracer(name=__name__) |
| 54 | +logger = _fastcs_logger.bind(logger_name=__name__) |
| 55 | + |
42 | 56 |
|
43 | 57 | class FastCS: |
44 | 58 | """For launching a controller with given transport(s) and keeping |
@@ -149,6 +163,12 @@ async def serve(self) -> None: |
149 | 163 |
|
150 | 164 | coros.append(self._interactive_shell(context)) |
151 | 165 |
|
| 166 | + logger.info( |
| 167 | + "Starting FastCS", |
| 168 | + controller=self._controller, |
| 169 | + transports=f"[{', '.join(str(t) for t in self._transports)}]", |
| 170 | + ) |
| 171 | + |
152 | 172 | try: |
153 | 173 | await asyncio.gather(*coros) |
154 | 174 | except asyncio.CancelledError: |
@@ -237,9 +257,10 @@ def _add_attribute_updater_tasks( |
237 | 257 | def _create_updater_callback(attribute: AttrR[T]): |
238 | 258 | async def callback(): |
239 | 259 | try: |
| 260 | + tracer.log_event("Call attribute updater", topic=attribute) |
240 | 261 | await attribute.update() |
241 | | - except Exception as e: |
242 | | - print(f"Update loop in {attribute} stopped:\n{e.__class__.__name__}: {e}") |
| 262 | + except Exception: |
| 263 | + logger.opt(exception=True).error("Update loop failed", attribute=attribute) |
243 | 264 | raise |
244 | 265 |
|
245 | 266 | return callback |
@@ -381,10 +402,39 @@ def run( |
381 | 402 | help=f"A yaml file matching the {controller_class.__name__} schema" |
382 | 403 | ), |
383 | 404 | ], |
| 405 | + log_level: Annotated[ |
| 406 | + Optional[LogLevel], # noqa: UP045 |
| 407 | + typer.Option(), |
| 408 | + ] = None, |
| 409 | + graylog_endpoint: Annotated[ |
| 410 | + Optional[GraylogEndpoint], # noqa: UP045 |
| 411 | + typer.Option( |
| 412 | + help="Endpoint for graylog logging - '<host>:<port>'", |
| 413 | + parser=GraylogEndpoint.parse_graylog_endpoint, |
| 414 | + ), |
| 415 | + ] = None, |
| 416 | + graylog_static_fields: Annotated[ |
| 417 | + Optional[GraylogStaticFields], # noqa: UP045 |
| 418 | + typer.Option( |
| 419 | + help="Fields to add to graylog messages with static values", |
| 420 | + parser=parse_graylog_static_fields, |
| 421 | + ), |
| 422 | + ] = None, |
| 423 | + graylog_env_fields: Annotated[ |
| 424 | + Optional[GraylogEnvFields], # noqa: UP045 |
| 425 | + typer.Option( |
| 426 | + help="Fields to add to graylog messages from environment variables", |
| 427 | + parser=parse_graylog_env_fields, |
| 428 | + ), |
| 429 | + ] = None, |
384 | 430 | ): |
385 | 431 | """ |
386 | 432 | Start the controller |
387 | 433 | """ |
| 434 | + configure_logging( |
| 435 | + log_level, graylog_endpoint, graylog_static_fields, graylog_env_fields |
| 436 | + ) |
| 437 | + |
388 | 438 | controller_class = ctx.obj.controller_class |
389 | 439 | fastcs_options = ctx.obj.fastcs_options |
390 | 440 |
|
|
0 commit comments