@@ -218,6 +218,93 @@ On another terminal or computer, start the sender
218218- Registers handlers for text and file streams, logs stream events, computes one-way latency, and saves the received file locally.
219219
220220
221+ ## Logging
222+
223+ The SDK uses [ spdlog] ( https://github.com/gabime/spdlog ) internally but does
224+ ** not** expose it in public headers. All log output goes through a thin public
225+ API in ` <livekit/logging.h> ` .
226+
227+ ### Two-tier filtering
228+
229+ | Tier | When | How | Cost |
230+ | ------| ------| -----| ------|
231+ | ** Compile-time** | CMake configure | ` -DLIVEKIT_LOG_LEVEL=WARN ` | Zero -- calls below the level are stripped from the binary |
232+ | ** Runtime** | Any time after ` initialize() ` | ` livekit::setLogLevel(LogLevel::Warn) ` | Minimal -- a level check before formatting |
233+
234+ #### Compile-time level (` LIVEKIT_LOG_LEVEL ` )
235+
236+ Set once when you configure CMake. Calls below this threshold are completely
237+ removed by the preprocessor -- no format-string evaluation, no function call.
238+
239+ ``` bash
240+ # Development (default): keep everything available
241+ cmake -DLIVEKIT_LOG_LEVEL=TRACE ..
242+
243+ # Release: strip TRACE / DEBUG / INFO
244+ cmake -DLIVEKIT_LOG_LEVEL=WARN ..
245+
246+ # Production: only ERROR and CRITICAL survive
247+ cmake -DLIVEKIT_LOG_LEVEL=ERROR ..
248+ ```
249+
250+ Valid values: ` TRACE ` , ` DEBUG ` , ` INFO ` , ` WARN ` , ` ERROR ` , ` CRITICAL ` , ` OFF ` .
251+
252+ #### Runtime level (` setLogLevel ` )
253+
254+ Among the levels that survived compilation you can still filter at runtime
255+ without rebuilding:
256+
257+ ``` cpp
258+ #include < livekit/livekit.h>
259+
260+ livekit::initialize (); // default level: Info
261+ livekit::setLogLevel (livekit::LogLevel::Debug); // show more detail
262+ livekit::setLogLevel(livekit::LogLevel::Warn); // suppress info chatter
263+ ```
264+
265+ ### Custom log callback
266+
267+ Replace the default stderr sink with your own handler. This is the integration
268+ point for frameworks like ROS2 (`RCLCPP_*` macros), Android logcat, or any
269+ structured-logging pipeline:
270+
271+ ```cpp
272+ #include <livekit/livekit.h>
273+
274+ livekit::initialize();
275+ livekit::setLogLevel(livekit::LogLevel::Trace);
276+
277+ livekit::setLogCallback(
278+ [](livekit::LogLevel level,
279+ const std::string &logger_name,
280+ const std::string &message) {
281+ // Route to your framework, e.g.:
282+ // RCLCPP_INFO(get_logger(), "[%s] %s", logger_name.c_str(), message.c_str());
283+ myLogger.log(level, logger_name, message);
284+ });
285+
286+ // Pass nullptr to restore the default stderr sink:
287+ livekit::setLogCallback(nullptr);
288+ ```
289+
290+ See [ ` examples/logging_levels/custom_sinks.cpp ` ] ( examples/logging_levels/custom_sinks.cpp )
291+ for three copy-paste-ready patterns: ** file logger** , ** JSON structured lines** ,
292+ and a ** ROS2 bridge** that maps ` LogLevel ` to ` RCLCPP_* ` macros.
293+
294+ ### Available log levels
295+
296+ | Level | Typical use |
297+ | -------| -------------|
298+ | ` Trace ` | Per-frame / per-packet detail (very noisy) |
299+ | ` Debug ` | Diagnostic info useful during development |
300+ | ` Info ` | Normal operational messages (connection, track events) |
301+ | ` Warn ` | Unexpected but recoverable situations |
302+ | ` Error ` | Failures that affect functionality |
303+ | ` Critical ` | Unrecoverable errors |
304+ | ` Off ` | Suppress all output |
305+
306+ ---
307+
221308### 🧪 Integration & Stress Tests
222309
223310The SDK includes integration and stress tests using Google Test (gtest).
0 commit comments