This document explains how to initialize the WebRTC logging system, when it must be done, and the consequences of late initialization.
To initialize logging with custom settings, call webrtc::InitializeLogging and pass a webrtc::LoggingConfig object.
Initialization can happen only once.
Example:
#include "rtc_base/logging.h" int main() { webrtc::LoggingConfig config; config.set_min_severity(webrtc::LS_INFO); config.set_log_thread(true); config.set_log_timestamp(true); // Add custom sinks if needed // config.AddSink(std::make_unique<MyLogSink>()); if (!webrtc::InitializeLogging(std::move(config))) { // Handle initialization failure (e.g., called too late) } // Proceed with WebRTC usage }
Initialization must be performed before any other WebRTC API calls and before any logging occurs via RTC_LOG macros.
If not initialized explicitly, logging initialization will happen implicitly upon the first logging call (e.g., RTC_LOG) or any function that accesses the logging configuration. The defaults used for implicit initialization are defined in the LoggingConfig struct.
If InitializeLogging is called after the logging system has already been initialized (implicitly or explicitly):
false.LoggingConfig will be ignored.To avoid this, ensure InitializeLogging is called as early as possible in the application's startup sequence.