This library provides a Python logging formatter designed to output log data as JSON objects compatible with Logstash json filters. It enables standard Python logging to produce structured logs that can be easily ingested and parsed by Logstash. The current version is 0.1.2, released in 2018, indicating a low or inactive release cadence.
pip install logstash_formatterVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure the standard Python logging module to use `LogstashFormatterV1`. It sets up a basic logger with a stream handler, applies the formatter, and shows examples of logging simple messages, messages with extra fields, and exceptions, all formatted as JSON. The `LogstashFormatterV1` handles conversion of `msg` to `@message` and integrates `extra` dictionary fields.
Always use `logstash_formatter` for installation and imports.
Be aware that direct message strings become `message`, while dictionaries passed as `msg` are flattened. Use the `extra` parameter for additional structured data alongside a string message.
Consult Python's `logging.Formatter` documentation for a list of reserved `LogRecord` attributes. Prefix custom `extra` fields (e.g., `my_app_field`) to avoid conflicts.
For new projects or if encountering limitations, consider evaluating `python-logstash` or `python-logstash-async` as alternatives, especially if asynchronous logging or newer Logstash features are required.
Ensure you installed with `pip install logstash_formatter` and imported with `from logstash_formatter import ...`.
The `LogstashFormatter` has a `json_default` parameter. By default, it coerces unknown types to strings. If you have custom objects, either ensure they are converted to strings/JSON-serializable types before logging, or provide a custom `json_default` callable to the `LogstashFormatterV1` constructor to handle their serialization.
Use `LogstashFormatterV1` explicitly as it handles the `msg` to `message` conversion for Logstash 1.2.0 schema. Ensure your Logstash input configuration is set up to parse JSON correctly and expects the `message` field.
No dependency data recorded yet.