fastcs.logging#
Members
Configure FastCS logger |
|
Intercept std logging messages from the given logger |
|
FastCS logger |
- fastcs.logging.logger = <loguru.logger handlers=[(id=0, level=10, sink=<stderr>)]>#
FastCS logger
This is a singleton logger instance to be used throughout the library and in specific drivers. This logger uses
loguruas underlying logging library, which enables much simpler configuration as well as structured logging.Keyword arguments to log statements 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.
from fastcs.logging import logger logger.info("PV put: {pv} = {value}", pv=pv, value=value)
To add kwargs to format the message without them appearing as extra fields, prepend the key with
_.By default messages will be logged with the name
fastcs. Within a driver it may be useful to set a distinct logger name. This can be done with thebindmethod. To create a new logger with the the name of the driver, use the following in a logging.py module and use it throughout the package instead of the fastcs logger:from fastcs.logging import logger as _logger logger = _logger.bind(logger_name="fastcs-driver")
As standard
logurusupportstracelevel monitoring, but it should not be used in fastcs. Instead there is aTracerclass for verbose logging with fine-grained controls that can be enabled by the user at runtime.Use
configure_loggingto re-configure the logger at runtime. For more advanced controls, configure theloggersingleton directly.See the
logurudocs for more information: https://loguru.readthedocs.io
- fastcs.logging.configure_logging(level: LogLevel = LogLevel.INFO, 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_namefor a message. Add a breakpoint inlogging.Logger.callHandlers, debug and run until the log message appears asrecord.msg. The logger name will be inself.name.- Parameters:
logger_name – Name of the logger to intercept