mozlog is a Python library from Mozilla designed for robust, structured logging, particularly within test harnesses and the broader Mozilla ecosystem. It outputs a stream of JSON-compatible objects, making it distinct from the standard `logging` module. As of version 8.1.0, it remains actively maintained with regular updates.
pip install mozlogVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `mozlog` using `setup_logging` and emit various types of structured log messages. The `setup_logging` function provides a convenient way to initialize the logger with default handlers and formatters, often sending JSON output to stdout.
Familiarize yourself with the `mozlog` API and its structured JSON message format, rather than assuming `stdlib` `logging` patterns.
Design your multi-process application to centralize all `mozlog` calls within a single, dedicated logging process or thread, passing messages to it via inter-process communication.
Ensure `mozlog.commandline.setup_logging()` or `mozlog.structuredlog.set_default_logger()` is called at application startup before any `ProxyLogger` instances are used.
When using `mozlog`, generally create only one `StructuredLogger` instance or rely on the default logger set by `setup_logging` to avoid unexpected state sharing or configuration conflicts.
When integrating with cloud logging services, verify the mapping of `mozlog`'s severity actions to the external system's levels. Custom remapping or a wrapper might be necessary.
Call `mozlog.commandline.setup_logging()` early in your application's lifecycle to ensure the default logger is properly initialized. For example: `logger = setup_logging()`.
To configure the Python `mozlog` library, use its dedicated API (e.g., `setup_logging` parameters, `StructuredLogger` methods) or adjust the handlers/formatters programmatically. The `MOZ_LOG` environment variable has no effect on this Python library.
Review the `mozlog` documentation for its specific methods for adding handlers (`mozlog.commandline.setup_handlers`) and configuring output, which are distinct from the `stdlib` `logging` module. You interact with `mozlog` by calling specific action methods like `info`, `warning`, `test_start`, etc., which accept structured data.
No dependency data recorded yet.