@ -254,28 +254,29 @@ TEST_F(AutoRollLoggerTest, InfoLogLevel) {
// becomes out of scope.
{
AutoRollLogger logger ( Env : : Default ( ) , kTestDir , " " , log_size , 0 ) ;
for ( int log_level = InfoLogLevel : : FATAL _LEVEL;
for ( int log_level = InfoLogLevel : : HEADER _LEVEL;
log_level > = InfoLogLevel : : DEBUG_LEVEL ; log_level - - ) {
logger . SetInfoLogLevel ( ( InfoLogLevel ) log_level ) ;
for ( int log_type = InfoLogLevel : : DEBUG_LEVEL ;
log_type < = InfoLogLevel : : FATAL _LEVEL; log_type + + ) {
log_type < = InfoLogLevel : : HEADER _LEVEL; log_type + + ) {
// log messages with log level smaller than log_level will not be
// logged.
LogMessage ( ( InfoLogLevel ) log_type , & logger , kSampleMessage . c_str ( ) ) ;
}
log_lines + = InfoLogLevel : : FATAL _LEVEL - log_level + 1 ;
log_lines + = InfoLogLevel : : HEADER _LEVEL - log_level + 1 ;
}
for ( int log_level = InfoLogLevel : : FATAL _LEVEL;
for ( int log_level = InfoLogLevel : : HEADER _LEVEL;
log_level > = InfoLogLevel : : DEBUG_LEVEL ; log_level - - ) {
logger . SetInfoLogLevel ( ( InfoLogLevel ) log_level ) ;
// again, messages with level smaller than log_level will not be logged.
Log ( InfoLogLevel : : HEADER_LEVEL , & logger , " %s " , kSampleMessage . c_str ( ) ) ;
Debug ( & logger , " %s " , kSampleMessage . c_str ( ) ) ;
Info ( & logger , " %s " , kSampleMessage . c_str ( ) ) ;
Warn ( & logger , " %s " , kSampleMessage . c_str ( ) ) ;
Error ( & logger , " %s " , kSampleMessage . c_str ( ) ) ;
Fatal ( & logger , " %s " , kSampleMessage . c_str ( ) ) ;
log_lines + = InfoLogLevel : : FATAL _LEVEL - log_level + 1 ;
log_lines + = InfoLogLevel : : HEADER _LEVEL - log_level + 1 ;
}
}
std : : ifstream inFile ( AutoRollLoggerTest : : kLogFile . c_str ( ) ) ;
@ -329,19 +330,31 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
static const size_t LOG_MAX_SIZE = 1024 * 5 ;
static const std : : string HEADER_STR = " Log header line " ;
// test_num == 0 -> standard call to Header()
// test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL
for ( int test_num = 0 ; test_num < 2 ; test_num + + ) {
InitTestDb ( ) ;
AutoRollLogger logger ( Env : : Default ( ) , kTestDir , /*db_log_dir=*/ " " ,
LOG_MAX_SIZE , /*log_file_time_to_roll=*/ 0 ) ;
// log some headers
if ( test_num = = 0 ) {
// Log some headers explicitly using Header()
for ( size_t i = 0 ; i < MAX_HEADERS ; i + + ) {
Header ( & logger , " %s %d " , HEADER_STR . c_str ( ) , i ) ;
}
} else if ( test_num = = 1 ) {
// HEADER_LEVEL should make this behave like calling Header()
for ( size_t i = 0 ; i < MAX_HEADERS ; i + + ) {
Log ( InfoLogLevel : : HEADER_LEVEL , & logger , " %s %d " ,
HEADER_STR . c_str ( ) , i ) ;
}
}
const string & newfname = logger . TEST_log_fname ( ) . c_str ( ) ;
// log enough data to cause a roll over
// L og enough data to cause a roll over
int i = 0 ;
for ( size_t iter = 0 ; iter < 2 ; iter + + ) {
while ( logger . GetLogFileSize ( ) < LOG_MAX_SIZE ) {
@ -352,7 +365,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
Info ( & logger , " Rollover " ) ;
}
// Flus the log for the latest file
// Flush the log for the latest file
LogFlush ( & logger ) ;
const list < string > oldfiles = GetOldFileNames ( newfname ) ;
@ -366,6 +379,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
ASSERT_EQ ( GetLinesCount ( oldfname , HEADER_STR ) , MAX_HEADERS ) ;
}
}
}
TEST_F ( AutoRollLoggerTest , LogFileExistence ) {
rocksdb : : DB * db ;