Console logging
Mellea usesMelleaLogger, a color-coded singleton logger built on Python’s
logging module. All internal Mellea modules obtain their logger via
MelleaLogger.get_logger().
Configuration
Note: IfBy default,MELLEA_LOGS_FILEis set but the path cannot be opened (for example due to a permissions error or an invalid path), Mellea emits aUserWarningand continues without file logging. The application is never crashed by a misconfigured log path.
MelleaLogger logs at INFO level with color-coded output to
stdout. Set MELLEA_LOGS_LEVEL to change the level:
Log format
Console output uses ANSI color codes by log level:- Cyan — DEBUG
- Grey — INFO
- Yellow — WARNING
- Red — ERROR
- Bold red — CRITICAL
Sample output
Console format (default)
Runningm.instruct(...) inside a session produces lines like:
JSON format (MELLEA_LOGS_JSON=1)
With structured JSON output enabled, the same SUCCESS record looks like:
session_id, backend, model_id, strategy, and loop_budget fields
are injected automatically when the call runs inside a with session: block.
They appear on every log record within that scope.
Adding custom context fields
Uselog_context to attach your own fields for the duration of a block:
OTLP log export
When the[telemetry] extra is installed, Mellea can export logs to an OTLP
collector alongside the existing console output. This is useful for centralizing
logs from distributed services.
Note: OTLP logging is disabled by default. When disabled, there is zero overhead — no OTLP handler is created.
Enable OTLP logging
How it works
WhenMELLEA_LOGS_OTLP=true, MelleaLogger adds an OpenTelemetry
LoggingHandler alongside its existing handlers:
- Console handler — continues to work normally (color-coded output)
- REST handler — continues to work normally (when
MELLEA_LOGS_WEBHOOKis set) - OTLP handler — exports logs to the configured OTLP collector
Programmatic access
Useget_otlp_log_handler() to add OTLP log export to your own loggers:
None when OTLP logging is disabled or not configured,
so the if handler check is always safe.
OTLP collector setup example
Integration with observability platforms
OTLP logs work with any OTLP-compatible platform:- Grafana Loki — log aggregation and querying
- Elasticsearch — log storage and analysis
- Datadog — unified logs, traces, and metrics
- New Relic — centralized logging
- Splunk — log analysis and monitoring
Performance
- Zero overhead when disabled: No OTLP handler is created, no performance impact.
- Batched export: Logs are batched and exported asynchronously.
- Non-blocking: Log export never blocks application code.
- Minimal overhead when enabled: OpenTelemetry’s efficient batching minimizes impact.
Troubleshooting
Logs not appearing in OTLP collector:- Verify
MELLEA_LOGS_OTLP=trueis set. - Check that an OTLP endpoint is configured
(
OTEL_EXPORTER_OTLP_ENDPOINTorOTEL_EXPORTER_OTLP_LOGS_ENDPOINT). - Verify the OTLP collector is running and configured to receive logs.
- Check collector logs for connection errors.
OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT.
Connection refused:
- Verify the OTLP collector is running:
docker ps | grep otel - Check the endpoint URL is correct (default:
http://localhost:4317). - Verify network connectivity:
curl http://localhost:4317
See also: