Apollo 10.0
自动驾驶开放平台
|
#include <async_logger.h>
Public 成员函数 | |
AsyncLogger (google::base::Logger *wrapped) | |
~AsyncLogger () | |
void | Start () |
start the async logger | |
void | Stop () |
Stop the thread. | |
void | Write (bool force_flush, time_t timestamp, const char *message, int message_len) override |
Write a message to the log. | |
void | Flush () override |
Flush any buffered messages. | |
uint32_t | LogSize () override |
Get the current LOG file size. | |
std::thread * | LogThread () |
get the log thead | |
Wrapper for a glog Logger which asynchronously writes log messages. This class starts a new thread responsible for forwarding the messages to the logger, and performs double buffering. Writers append to the current buffer and then wake up the logger thread. The logger swaps in a new buffer and writes any accumulated messages to the wrapped Logger.
This double-buffering design dramatically improves performance, especially for logging messages which require flushing the underlying file (i.e WARNING and above for default). The flush can take a couple of milliseconds, and in some cases can even block for hundreds of milliseconds or more. With the double-buffered approach, threads can proceed with useful work while the IO thread blocks.
The semantics provided by this wrapper are slightly weaker than the default glog semantics. By default, glog will immediately (synchronously) flush WARNING and above to the underlying file, whereas here we are deferring that flush to a separate thread. This means that a crash just after a 'LOG_WARN' would may be missing the message in the logs, but the perf benefit is probably worth it. We do take care that a glog FATAL message flushes all buffered log messages before exiting.
在文件 async_logger.h 第 73 行定义.
|
explicit |
在文件 async_logger.cc 第 34 行定义.
apollo::cyber::logger::AsyncLogger::~AsyncLogger | ( | ) |
在文件 async_logger.cc 第 39 行定义.
|
override |
Flush any buffered messages.
在文件 async_logger.cc 第 81 行定义.
|
override |
Get the current LOG file size.
The return value is an approximate value since some logged data may not have been flushed to disk yet.
在文件 async_logger.cc 第 87 行定义.
|
inline |
get the log thead
在文件 async_logger.h 第 126 行定义.
void apollo::cyber::logger::AsyncLogger::Start | ( | ) |
start the async logger
在文件 async_logger.cc 第 41 行定义.
void apollo::cyber::logger::AsyncLogger::Stop | ( | ) |
Stop the thread.
Flush() and Write() must not be called after this. NOTE: this is currently only used in tests: in real life, we enable async logging once when the program starts and then never disable it. REQUIRES: Start() must have been called.
在文件 async_logger.cc 第 48 行定义.
|
override |
Write a message to the log.
Start() must have been called.
force_flush | is set by the GLog library based on the configured '–logbuflevel' flag. Any messages logged at the configured level or higher result in 'force_flush' being set to true, indicating that the message should be immediately written to the log rather than buffered in memory. |
timestamp | is the time of write a message |
message | is the info to be written |
message_len | is the length of message |
在文件 async_logger.cc 第 60 行定义.