@ -13,17 +13,17 @@ LogBuffer::LogBuffer(const InfoLogLevel log_level,
Logger * info_log )
: log_level_ ( log_level ) , info_log_ ( info_log ) { }
void LogBuffer : : AddLogToBuffer ( const char * format , va_list ap ) {
void LogBuffer : : AddLogToBuffer ( size_t max_log_size , const char * format ,
va_list ap ) {
if ( ! info_log_ | | log_level_ < info_log_ - > GetInfoLogLevel ( ) ) {
// Skip the level because of its level.
return ;
}
const size_t kLogSizeLimit = 512 ;
char * alloc_mem = arena_ . AllocateAligned ( kLogSizeLimit ) ;
char * alloc_mem = arena_ . AllocateAligned ( max_log_size ) ;
BufferedLog * buffered_log = new ( alloc_mem ) BufferedLog ( ) ;
char * p = buffered_log - > message ;
char * limit = alloc_mem + kLogSizeLimit - 1 ;
char * limit = alloc_mem + max_log_size - 1 ;
// store the time
gettimeofday ( & ( buffered_log - > now_tv ) , nullptr ) ;
@ -61,11 +61,22 @@ void LogBuffer::FlushBufferToLog() {
logs_ . clear ( ) ;
}
void LogToBuffer ( LogBuffer * log_buffer , size_t max_log_size , const char * format ,
. . . ) {
if ( log_buffer ! = nullptr ) {
va_list ap ;
va_start ( ap , format ) ;
log_buffer - > AddLogToBuffer ( max_log_size , format , ap ) ;
va_end ( ap ) ;
}
}
void LogToBuffer ( LogBuffer * log_buffer , const char * format , . . . ) {
const size_t kDefaultMaxLogSize = 512 ;
if ( log_buffer ! = nullptr ) {
va_list ap ;
va_start ( ap , format ) ;
log_buffer - > AddLogToBuffer ( format , ap ) ;
log_buffer - > AddLogToBuffer ( kDefaultMaxLogSize , format , ap ) ;
va_end ( ap ) ;
}
}