oslo.log is a Python library that provides standardized logging configuration for OpenStack projects. It offers custom formatters, handlers, and support for context-specific logging, enhancing the standard Python logging module. The current version is 8.1.0 and it's actively maintained by the OpenStack community with regular releases.
pip install oslo.logVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic setup and usage of oslo.log. It involves importing `cfg` from `oslo_config` to manage configuration options, registering `oslo.log`'s options, and then initializing the logging system with `logging.setup()`. Finally, it shows how to obtain a logger and emit messages at different levels.
If you intend to use a logging configuration file, define all logging settings within that file. If you prefer `oslo.log`'s programmatic or `oslo.config` options, do not set `log_config_append`.
To modify the `logging_default_format_string` (for logs without context), use `CONF.set_override('logging_default_format_string', 'YOUR_FORMAT_STRING')` or define it in your `oslo.config` configuration file under the `[DEFAULT]` section. The `logging_context_format_string` is used when an `oslo.context` object is attached to the log message.Be aware that applications relying on the exact syslog message format may need adjustments in the future. Monitor `oslo.log` release notes for details on when the RFC5424 change is implemented. This option is ignored if `log_config_append` is set.
Install the library using pip: `pip install oslo.log`.
Rename your Python script or any conflicting local file that might be named `logging.py` to avoid collision with the standard library.
Configure logging using `oslo_log.setup()` with an `oslo_config.cfg.ConfigOpts` object, or ensure `logging.basicConfig()` is called before `oslo_log` or any other library configures the root logger.
To modify the format for regular log lines, use `CONF.set_override('logging_default_format_string', 'YOUR_FORMAT_STRING')` before calling `oslo_log.setup()`, or specify it directly in your configuration file.