Kea  1.5.0
log_utils.cc
Go to the documentation of this file.
1 // Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <testutils/log_utils.h>
10 #include <iostream>
11 
12 namespace isc {
13 namespace dhcp {
14 namespace test {
15 
17  :verbose_(false) {
18  // Get rid of any old files
19  remFile();
20 
21  // Set up the logger for use in checking the debug statements.
22  // We send the debug statements to a file which we can
23  // check after the evaluations have completed. We also
24  // set the log severity and debug levels so that the log
25  // statements are executed.
29  OutputOption option;
30  option.destination = OutputOption::DEST_FILE;
31  option.filename = string(LogContentTest::LOG_FILE);
32  spec.addOutputOption(option);
33  LoggerManager manager;
34  manager.process(spec);
35 }
36 
38  remFile();
39 }
40 
42  ifstream file(LOG_FILE);
43  EXPECT_TRUE(file.is_open());
44  string line, exp_line;
45  int i = 0;
46  bool found = true;
47 
48  using namespace std;
49 
50  while (getline(file, line) && (i != exp_strings_.size())) {
51  exp_line = exp_strings_[i];
52  if (verbose_) {
53  cout << "Read line :" << line << endl;
54  cout << "Looking for:" << exp_line << endl;
55  }
56  i++;
57  if (string::npos == line.find(exp_line)) {
58  if (verbose_) {
59  cout << "Verdict : not found" << endl;
60  }
61  found = false;
62  }
63  }
64 
65  file.close();
66 
67  if ((i != exp_strings_.size()) || (found == false)) {
68  if (verbose_) {
69  cout << "Final verdict: false" << endl;
70  }
71  return (false);
72  }
73 
74  return (true);
75 }
76 
78  static_cast<void>(remove(LOG_FILE));
79 }
80 
81 void LogContentTest::addString(const string& new_string) {
82  exp_strings_.push_back(new_string);
83 }
84 
85 // Set up the name of the LOG_FILE for use in checking
86 // the debug statements
87 const char *LogContentTest::LOG_FILE = "test.log";
88 
89 }; // end of isc::dhcp::test namespace
90 }; // end of isc::dhcp namespace
91 }; // end of isc namespace
const std::string & getRootLoggerName()
Get root logger name.
Definition: logger_name.cc:33
void addOutputOption(const OutputOption &option)
Add output option.
isc::log::Severity keaLoggerSeverity(isc::log::Severity defseverity)
Obtains logging severity from KEA_LOGGER_SEVERITY.
void addString(const string &new_string)
Add a string to the vector of expected strings.
Definition: log_utils.cc:81
void process(T start, T finish)
Process Specifications.
int keaLoggerDbglevel(int defdbglevel)
Obtains logging debug level from KEA_LOGGER_DBGLEVEL.
static const char * LOG_FILE
Definition: log_utils.h:82
bool verbose_
controls whether the checkFile() should print more details.
Definition: log_utils.h:90
LogContentTest()
Initializes the logger setup for using in checking log statements.
Definition: log_utils.cc:16
Destination destination
Members.
Definition: output_option.h:61
vector< string > exp_strings_
Definition: log_utils.h:81
Defines the logger used by the top-level component of kea-dhcp-ddns.
void remFile()
remove the test log file
Definition: log_utils.cc:77
bool checkFile()
check that the requested strings are in the test log file in the requested order.
Definition: log_utils.cc:41
std::string filename
Filename if file output.
Definition: output_option.h:65
const int MAX_DEBUG_LEVEL
Definition: logger_level.h:36