Expand description
UDP logger for sending log messages to autocore-server.
This module provides a non-blocking logger implementation that sends log messages via UDP to the autocore-server. Messages are batched and sent asynchronously to avoid impacting control loop timing.
§Example
use autocore_std::logger;
use log::LevelFilter;
// Initialize the logger (done automatically by ControlRunner)
logger::init_udp_logger("127.0.0.1", 39101, LevelFilter::Info, "control")?;
// Now you can use the log macros
log::info!("System initialized");UDP Logger for Control Programs
This module provides a logger implementation that sends log messages via UDP to the autocore-server for display in the console. The logger is designed to be non-blocking and fire-and-forget to avoid impacting the control loop timing.
§Overview
When you use log::info!, log::warn!, etc. in your control program,
the messages are sent to the autocore-server where they appear in the web
console’s log panel. This allows you to monitor your control program in
real-time without needing direct access to stdout.
§Architecture
┌─────────────────────────────┐
│ Control Program Process │
│ ┌───────────────────────┐ │
│ │ UdpLogger │ │
│ │ (implements log::Log) │ │
│ └──────────┬────────────┘ │
│ │ mpsc channel │
│ ┌──────────▼────────────┐ │
│ │ Background thread │ │
│ │ (batches & sends UDP) │ │
│ └──────────┬────────────┘ │
└─────────────┼───────────────┘
│ UDP (fire-and-forget)
▼
┌─────────────────────────────┐
│ autocore-server │
│ (UDP listener on 39101) │
└─────────────────────────────┘§Automatic Initialization
When using ControlRunner, the logger is initialized
automatically. You can configure the log level via RunnerConfig::log_level.
§Manual Initialization
If you need to initialize the logger manually (e.g., for testing):
use autocore_std::logger;
use log::LevelFilter;
logger::init_udp_logger("127.0.0.1", 39101, LevelFilter::Debug, "my_app")?;
log::debug!("Debug messages now visible!");
log::info!("Info messages too!");§Performance Considerations
- Log calls are non-blocking (messages are queued to a background thread)
- If the queue fills up (1000 messages), new messages are dropped silently
- Messages are batched and sent every 20ms or when 50 messages accumulate
- UDP is fire-and-forget: delivery is not guaranteed
Structs§
Constants§
- DEFAULT_
LOG_ UDP_ PORT - Default UDP port for log messages
Functions§
- init_
default_ logger - Initialize the UDP logger with default settings
- init_
udp_ logger - Initialize the UDP logger as the global logger