fastcs.logging#

Members

configure_logging

Configure FastCS logger

intercept_std_logger

Intercept std logging messages from the given logger

logger

FastCS logger

fastcs.logging.logger = <loguru.logger handlers=[(id=1, level=20, sink=<prompt_toolkit.patch_stdout.StdoutProxy object>)]>#

FastCS logger

This is a singleton logger instance to be used throughout the library and in specific drivers. This logger uses loguru as underlying logging library, which enables much simpler configuration as well as structured logging.

Keyword arguments to log statments will be attached as extra fields on the log record. These fields are displayed separately in the console output and can used for filtering and metrics in graylog.

It is best to keep the message short and use extra fields for additional information for messages to be formatted nicely in the console. To add kwargs to format the message without them appearing as extra fields, prepend the key with _.

from fastcs.logging import logger

logger.info("PV put: {pv} = {value}", pv=pv, value=value)

By default messages will be logged with the name fastcs. Within different modules and classes it can be useful to override this name. This can be done with the bind method. To create a module logger with its name

from fastcs.logging import logger as _logger

logger = _logger.bind(logger_name=__name__)

or to create a class logger with its name

self.logger = _logger.bind(logger_name=__class__.__name__)

As standard loguru supports trace level monitoring, but it should not be used in fastcs. Instead there is a Tracer class for verbose logging with fine-grained controls that can be enabled by the user at runtime.

Use configure_logging to re-confi the logger at runtime. For more advanced controls, configure the logger singleton directly.

See the loguru docs for more information: https://loguru.readthedocs.io

fastcs.logging.configure_logging(level: LogLevel | None = None, graylog_endpoint: GraylogEndpoint | None = None, graylog_static_fields: GraylogStaticFields | None = None, graylog_env_fields: GraylogEnvFields | None = None)[source]#

Configure FastCS logger

This function can be called at any time to
  • Change the console log level

  • Enable/disable graylog logging

Parameters:
  • level – Log level to set

  • graylog_endpoint – Endpoint for graylog logging - ‘<host>:<port>’

  • graylog_static_fields – Fields to add to graylog messages with static values

  • graylog_env_fields – Fields to add to graylog messages from env variables

fastcs.logging.intercept_std_logger(logger_name: str)[source]#

Intercept std logging messages from the given logger

To find the correct logger_name for a message. Add a breakpoint in logging.Logger.callHandlers, debug and run until the log message appears as record.msg. The logger name will be in self.name.

Parameters:

logger_name – Name of the logger to intercept