Kea  1.9.9-git
isc::dhcp::test::LogContentTest Class Reference

Test class for testing things that emit log entries. More...

#include <log_utils.h>

+ Inheritance diagram for isc::dhcp::test::LogContentTest:

Public Member Functions

 LogContentTest ()
 Initializes the logger setup for using in checking log statements. More...
 
virtual ~LogContentTest ()
 
void addString (const string &new_string)
 Add a string to the vector of expected strings. More...
 
bool checkFile ()
 check that the requested strings are in the test log file in the requested order. More...
 
size_t countFile (const string &exp_string)
 check that the requested string is in the test log file. More...
 
void logCheckVerbose (bool talk_a_lot)
 Enables or disables verbose mode. More...
 
void remFile ()
 remove the test log file More...
 

Public Attributes

vector< string > exp_strings_
 
bool verbose_
 controls whether the checkFile() should print more details. More...
 

Static Public Attributes

static const char * KEA_LOG_CHECK_VERBOSE = "KEA_LOG_CHECK_VERBOSE"
 
static const char * LOG_FILE = "logtest.log"
 

Detailed Description

Test class for testing things that emit log entries.

This class provides a convenient method for testing out things that emit log entries. The class sets up the logging to log everything into a file and provides a routine to check the expected strings vs the actual log entries. The user needs to call the addString function for each of the strings they expect in the output in the order they will be emitted.

Definition at line 40 of file log_utils.h.

Constructor & Destructor Documentation

isc::dhcp::test::LogContentTest::LogContentTest ( )

Initializes the logger setup for using in checking log statements.

Todo:
add support to adjust the severity and debug level to allow for better control over the statements that get logged.

Definition at line 17 of file log_utils.cc.

References isc::log::LoggerSpecification::addOutputOption(), isc::log::DEBUG, isc::log::OutputOption::destination, isc::log::OutputOption::filename, isc::log::getRootLoggerName(), KEA_LOG_CHECK_VERBOSE, isc::log::keaLoggerDbglevel(), isc::log::keaLoggerSeverity(), LOG_FILE, isc::log::MAX_DEBUG_LEVEL, isc::log::LoggerManager::process(), remFile(), and verbose_.

+ Here is the call graph for this function:

isc::dhcp::test::LogContentTest::~LogContentTest ( )
virtual

Definition at line 44 of file log_utils.cc.

References remFile().

+ Here is the call graph for this function:

Member Function Documentation

void isc::dhcp::test::LogContentTest::addString ( const string &  new_string)

Add a string to the vector of expected strings.

Parameters
new_stringthe string to add to the end of the vector
Returns
void

Definition at line 117 of file log_utils.cc.

References exp_strings_.

bool isc::dhcp::test::LogContentTest::checkFile ( )

check that the requested strings are in the test log file in the requested order.

This routine expects that the caller has properly set up the vector of expected strings by calling addString() with the necessary strings.

Returns
true if all of the strings match

Definition at line 48 of file log_utils.cc.

References exp_strings_, LOG_FILE, and verbose_.

size_t isc::dhcp::test::LogContentTest::countFile ( const string &  exp_string)

check that the requested string is in the test log file.

Parameters
exp_stringthe string to be searched
Returns
count of matching lines

Definition at line 84 of file log_utils.cc.

References LOG_FILE, and verbose_.

void isc::dhcp::test::LogContentTest::logCheckVerbose ( bool  talk_a_lot)
inline

Enables or disables verbose mode.

See verbose_ for details.

Parameters
talk_a_lot(true - as the name says, false - shut up)

Definition at line 78 of file log_utils.h.

void isc::dhcp::test::LogContentTest::remFile ( )

remove the test log file

Definition at line 113 of file log_utils.cc.

References LOG_FILE.

Referenced by LogContentTest(), and ~LogContentTest().

Member Data Documentation

vector<string> isc::dhcp::test::LogContentTest::exp_strings_

Definition at line 88 of file log_utils.h.

Referenced by addString(), and checkFile().

const char * isc::dhcp::test::LogContentTest::KEA_LOG_CHECK_VERBOSE = "KEA_LOG_CHECK_VERBOSE"
static

Definition at line 90 of file log_utils.h.

Referenced by LogContentTest().

const char * isc::dhcp::test::LogContentTest::LOG_FILE = "logtest.log"
static

Definition at line 89 of file log_utils.h.

Referenced by checkFile(), countFile(), LogContentTest(), and remFile().

bool isc::dhcp::test::LogContentTest::verbose_

controls whether the checkFile() should print more details.

If set to true, checkFile() will print each expected line, each logged line and will print out a failure message if those two do not match. Also, a final verdict is printed. Everything is printed on stdout. The default is false but can be overwritten by setting the KEA_LOG_CHECK_VERBOSE environment variable.

Definition at line 100 of file log_utils.h.

Referenced by checkFile(), countFile(), and LogContentTest().


The documentation for this class was generated from the following files: