Kea 2.5.8
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.
 
virtual ~LogContentTest ()
 
void addString (const string &logger_msg, const string &new_string, Pkt &pkt)
 Generates and adds a string to the vector of expected strings.
 
void addString (const string &new_string)
 Add a string to the vector of expected strings.
 
bool checkFile ()
 check that the requested strings are in the test log file in the requested order.
 
size_t countFile (const string &exp_string)
 check that the requested string is in the test log file.
 
void logCheckVerbose (bool talk_a_lot)
 Enables or disables verbose mode.
 
void remFile ()
 remove the test log file
 

Public Attributes

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

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 42 of file log_utils.h.

Constructor & Destructor Documentation

◆ LogContentTest()

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::DEST_FILE, 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:

◆ ~LogContentTest()

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

◆ addString() [1/2]

void isc::dhcp::test::LogContentTest::addString ( const string &  logger_msg,
const string &  new_string,
Pkt pkt 
)

Generates and adds a string to the vector of expected strings.

Parameters
logger_msglogger message that will be prepended to the string
new_stringthe string used to generate the outcome
pktreference to the packet for which the message is generated

Definition at line 121 of file log_utils.cc.

References exp_strings_, and isc::dhcp::Pkt::getLabel().

+ Here is the call graph for this function:

◆ addString() [2/2]

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

Definition at line 117 of file log_utils.cc.

References exp_strings_.

◆ checkFile()

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_.

◆ countFile()

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_.

◆ logCheckVerbose()

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 80 of file log_utils.h.

References verbose_.

◆ remFile()

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

◆ exp_strings_

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

Definition at line 96 of file log_utils.h.

Referenced by addString(), and checkFile().

◆ KEA_LOG_CHECK_VERBOSE

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

Definition at line 98 of file log_utils.h.

Referenced by LogContentTest().

◆ LOG_FILE

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

Definition at line 97 of file log_utils.h.

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

◆ verbose_

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 108 of file log_utils.h.

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


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