fastcs.logging#
Members
Create a wrapper of the singleton fastcs logger with the given name bound |
|
Configure FastCS logger |
|
Intercept std logging messages from the given 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
loguruas 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 thebindmethod. To create a module logger with its namefrom 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
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.bind_logger(logger_name: str) Any[source]#
Create a wrapper of the singleton fastcs logger with the given name bound
The name will be displayed in all log messages from the returned wrapper.
See the docstring for
fastcs.logging.loggerfor more information.
- 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_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