{"id":5001,"library":"oslo-log","title":"Oslo Logging Library","description":"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.","status":"active","version":"8.1.0","language":"python","source_language":"en","source_url":"https://github.com/openstack/oslo.log","tags":["logging","openstack","configuration","log management","structured logging"],"install":[{"cmd":"pip install oslo.log","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for defining and managing configuration options for logging.","package":"oslo.config","optional":false},{"reason":"Provides helpers to maintain request context information, which oslo.log uses for context-specific logging.","package":"oslo.context","optional":true}],"imports":[{"symbol":"log","correct":"from oslo_log import log"},{"note":"oslo.log relies on oslo.config for its configuration management.","symbol":"cfg","correct":"from oslo_config import cfg"}],"quickstart":{"code":"import os\nfrom oslo_config import cfg\nfrom oslo_log import log as logging\n\n# Define a configuration group and options (typically done in a separate config file)\nCONF = cfg.CONF\nCONF.register_group(cfg.OptGroup('DEFAULT'))\n\n# Register oslo.log options (required for oslo.log to pick up config)\nlogging.register_options(CONF)\n\n# Set up logging for your application\n# The 'product_name' is usually your application's name\n# The 'version' is your application's version\nDOMAIN = os.environ.get('OSLO_LOG_DOMAIN', 'my_app') # Example for context\nlogging.setup(CONF, DOMAIN, version='1.0.0')\n\n# Get a logger instance\nLOG = logging.getLogger(__name__)\n\n# Log messages\nLOG.info(\"This is an informational message.\")\nLOG.warning(\"This is a warning message.\")\nLOG.error(\"This is an error message.\")\n\n# Example of setting a default log level (if not using a config file)\n# This would typically be done via a config file or oslo.config options\n# For demonstration, setting it programmatically (ensure it's before logging.setup if permanent)\n# logging.set_defaults(default_log_levels=['my_app=DEBUG'])\n","lang":"python","description":"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."},"warnings":[{"fix":"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`.","message":"When `log_config_append` is specified, all other logging configuration options (e.g., `log_date_format`, `log_file`, `use_syslog`, `default_log_levels`) are ignored. Logging is fully controlled by the specified configuration file.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Changing log format strings can be tricky, especially distinguishing between `logging_context_format_string` and `logging_default_format_string`. `log.set_defaults()` only affects the context-based format string.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"The existing syslog format used by `oslo.log` is deprecated and will be changed to honor RFC5424 in future versions.","severity":"deprecated","affected_versions":"Versions 7.0.0 and later"}],"env_vars":null,"search_vec":"'8.1.0':39 'activ':43 'communiti':48 'configur':13,54 'context':26 'context-specif':25 'current':36 'custom':19 'enhanc':29 'formatt':20 'handler':21 'librari':3,8 'log':2,12,28,33,52,55,58 'maintain':44 'manag':56 'modul':34 'offer':18 'openstack':15,47,53 'oslo':1 'oslo.log':4 'project':16 'provid':10 'python':7,32 'regular':50 'releas':51 'specif':27 'standard':11,31 'structur':57 'support':23 'version':37","created_at":"2026-04-12T16:49:49.865856+00:00","updated_at":"2026-04-16T17:49:35.618279+00:00","problems":[{"fix":"Install the library using pip: `pip install oslo.log`.","cause":"The 'oslo.log' library is not installed in your Python environment or is not accessible within the current `PYTHONPATH`.","error":"ModuleNotFoundError: No module named 'oslo_log'"},{"fix":"Rename your Python script or any conflicting local file that might be named `logging.py` to avoid collision with the standard library.","cause":"This typically occurs when a local Python file is inadvertently named `logging.py`, shadowing the standard Python `logging` module and causing incorrect imports.","error":"AttributeError: 'module' object has no attribute 'getLogger'"},{"fix":"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.","cause":"`oslo.log` takes control of the logging configuration. If `logging.basicConfig()` is called after `oslo.log`'s `setup()` function has initialized, or if other handlers are already present on the root logger, `basicConfig()` will have no effect.","error":"logging.basicConfig() has no effect (oslo.log is not configured as expected)"},{"fix":"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.","cause":"`oslo.log` distinguishes between log messages with an `oslo.context` attached (`logging_context_format_string`) and standard messages (`logging_default_format_string`). Changes made via `log.set_defaults()` primarily affect context-aware formats, leaving regular log lines unchanged.","error":"Cannot change oslo_log log format (e.g., 'logging_default_format_string' not applied)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"8.3.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://docs.openstack.org/oslo.log","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/oslo-log/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["observability","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-28","install_tag":null}}