Eliot.Logger (Eliot v0.2.0)
View SourceCentralized logging for the Eliot IoT data ingestion system.
Provides structured logging with telemetry integration for comprehensive observability of device communications, data processing, and system events.
Features
- Structured logging with metadata enrichment
- Telemetry event integration for system monitoring
- Device-specific event tracking
- MQTT connection lifecycle logging
- Data processing performance metrics
- Automatic statistics reporting
Usage
# Basic logging
Eliot.Logger.log_info("System started", %{component: "application"})
Eliot.Logger.log_error("Connection failed", %{retry_count: 3})
# Device event logging
Eliot.Logger.log_device_event("sensor_001", "temperature_reading", %{
temperature: 23.5,
humidity: 65.0
})
# MQTT event logging
broker_config = %{host: "mqtt.example.com", port: 1883}
Eliot.Logger.log_mqtt_event("connection_established", broker_config)
# Processing event logging
Eliot.Logger.log_processing_event("msg_123", 150, "success")
All logging functions automatically emit corresponding telemetry events for integration with monitoring and alerting systems.
Summary
Functions
Returns a specification to start this module under a supervisor.
Handles telemetry events for system-wide logging.
Logs device-specific events with standardized metadata.
Logs an error-level message with structured metadata.
Logs an info-level message with structured metadata.
Logs MQTT-related events with connection metadata.
Logs data processing events with performance metrics.
Logs a warning-level message with structured metadata.
Starts the logger GenServer.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Handles telemetry events for system-wide logging.
This function is defined as a module function to avoid the telemetry performance warning about local functions.
Logs device-specific events with standardized metadata.
Automatically enriches the event with timestamp and device information, then emits a telemetry event for monitoring systems.
Parameters
device_id
- Unique identifier for the deviceevent_type
- Type of event (e.g., "sensor_reading", "connection_lost")data
- Optional event-specific data (default:%{}
)
Examples
# Simple device event
Eliot.Logger.log_device_event("sensor_001", "online")
# Device event with sensor data
Eliot.Logger.log_device_event("thermometer_42", "temperature_reading", %{
temperature: 23.5,
humidity: 65.0,
battery_level: 87
})
Logs an error-level message with structured metadata.
Parameters
message
- The log message stringmetadata
- Optional map of structured metadata (default:%{}
)
Examples
Eliot.Logger.log_error("Database connection failed")
Eliot.Logger.log_error("API request timeout", %{endpoint: "/api/data", timeout_ms: 5000})
Logs an info-level message with structured metadata.
Parameters
message
- The log message stringmetadata
- Optional map of structured metadata (default:%{}
)
Examples
Eliot.Logger.log_info("System initialized successfully")
Eliot.Logger.log_info("User authenticated", %{user_id: "123", method: "oauth"})
Logs MQTT-related events with connection metadata.
Tracks MQTT broker interactions including connections, disconnections, message publishing, and subscription events.
Parameters
event_type
- Type of MQTT event (e.g., "connection_established", "message_published")broker_info
- Map containing broker connection detailsdata
- Optional event-specific data (default:%{}
)
Examples
broker_config = %{host: "mqtt.example.com", port: 1883, client_id: "eliot_001"}
# Connection event
Eliot.Logger.log_mqtt_event("connection_established", broker_config)
# Message publishing event
Eliot.Logger.log_mqtt_event("message_published", broker_config, %{
topic: "sensors/temperature",
qos: 1,
payload_size: 128
})
Logs data processing events with performance metrics.
Tracks message processing performance and outcomes for monitoring system throughput and identifying bottlenecks.
Parameters
message_id
- Unique identifier for the processed messageprocessing_time_ms
- Processing duration in millisecondsresult
- Processing outcome (e.g., "success", "error", "timeout")
Examples
# Successful processing
Eliot.Logger.log_processing_event("msg_12345", 150, "success")
# Failed processing
Eliot.Logger.log_processing_event("msg_12346", 2500, "timeout")
Logs a warning-level message with structured metadata.
Parameters
message
- The log message stringmetadata
- Optional map of structured metadata (default:%{}
)
Examples
Eliot.Logger.log_warning("High memory usage detected")
Eliot.Logger.log_warning("Rate limit approaching", %{current_rate: 95, limit: 100})
Starts the logger GenServer.
Options
:name
- The name to register the GenServer under (default:__MODULE__
)
Examples
{:ok, pid} = Eliot.Logger.start_link()
{:ok, pid} = Eliot.Logger.start_link(name: MyLogger)