9.3. Logging ThreadΒΆ

Calls to the macros presented in Logging Messages merely add the log entry to a ready-to-consume queue. Upon creation, the logging module spawns a thread that awakes every time an entry is added to the queue. When awaken, this thread feeds all the entries in the queue to all the registered Consumers. Once the work is done, the thread falls back into idle state. This strategy prevents the module from blocking the application thread when a logging operation is performed. However, sometimes applications may want to wait until the logging routine is done to continue their operation. The logging module provides this capability via the member function Log::Flush(). Furthermore, it is possible to completely eliminate the thread and its resources using member function Log::KillThread(). In addition, it is possible to configure certain settings of this logging thread via the member function Log::SetThreadConfig().

// Block current thread until the log queue is empty.
Log::Flush();

// Stop the loggin thread and free its resources.
Log::KillThread();

// Configure ThreadSettings for the logging thread
Log::SetThreadConfig(eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1});

Warning

A call to any of the macros present in Logging Messages will spawn the logging thread even if it has been previously killed with Log::KillThread().