Kea 2.7.5
logger_unittest_support.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2021 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 <iostream>
10#include <algorithm>
11#include <string>
12
13#include <log/logger_level.h>
14#include <log/logger_name.h>
15#include <log/logger_manager.h>
18#include <log/logger_support.h>
19#include <log/output_option.h>
20
21using namespace std;
22
23namespace isc {
24namespace log {
25
26// Get the logging severity. This is defined by the environment variable
27// KEA_LOGGER_SEVERITY, and can be one of "DEBUG", "INFO", "WARN", "ERROR"
28// of "FATAL". (Note that the string must be in upper case with no leading
29// of trailing blanks.) If not present, the default severity passed to the
30// function is returned.
33 const char* sev_char = getenv("KEA_LOGGER_SEVERITY");
34 if (sev_char) {
35 return (isc::log::getSeverity(sev_char));
36 }
37 return (defseverity);
38}
39
40// Get the debug level. This is defined by the environment variable
41// KEA_LOGGER_DBGLEVEL. If not defined, a default value passed to the function
42// is returned.
43int
44keaLoggerDbglevel(int defdbglevel) {
45 const char* dbg_char = getenv("KEA_LOGGER_DBGLEVEL");
46 if (dbg_char) {
47 int level = 0;
48 try {
49 level = boost::lexical_cast<int>(dbg_char);
50 if (level < MIN_DEBUG_LEVEL) {
51 std::cerr << "**ERROR** debug level of " << level
52 << " is invalid - a value of " << MIN_DEBUG_LEVEL
53 << " will be used\n";
54 level = MIN_DEBUG_LEVEL;
55 } else if (level > MAX_DEBUG_LEVEL) {
56 std::cerr << "**ERROR** debug level of " << level
57 << " is invalid - a value of " << MAX_DEBUG_LEVEL
58 << " will be used\n";
59 level = MAX_DEBUG_LEVEL;
60 }
61 } catch (...) {
62 // Error, but not fatal to the test
63 std::cerr << "**ERROR** Unable to translate "
64 "KEA_LOGGER_DBGLEVEL - a value of 0 will be used\n";
65 }
66 return (level);
67 }
68
69 return (defdbglevel);
70}
71
72// Logger Run-Time Initialization via Environment Variables
73void initLogger(isc::log::Severity severity, int dbglevel) {
74
75 // Root logger name is defined by the environment variable KEA_LOGGER_ROOT.
76 // If not present, the name is "kea".
77 const char* root = getenv("KEA_LOGGER_ROOT");
78 if (! root) {
79 // If not present, the name is "kea".
81 }
82
83 // Set the local message file
84 const char* localfile = getenv("KEA_LOGGER_LOCALMSG");
85
86 // Set a directory for creating lockfiles when running tests
87 setenv("KEA_LOCKFILE_DIR", TOP_BUILDDIR, 0);
88
89 // Initialize logging
90 initLogger(root, severity, dbglevel, localfile);
91
92 // Now set reset the output destination of the root logger, overriding
93 // the default severity, debug level and destination with those specified
94 // in the environment variables. (The two-step approach is used as the
95 // setUnitTestRootLoggerCharacteristics() function is used in several
96 // places in the Kea tests, and it avoid duplicating code.)
98}
99
100} // namespace log
101} // namespace isc
Logging initialization functions.
Miscellaneous logging functions used by the unit tests.
void initLogger(const string &root, isc::log::Severity severity, int dbglevel, const char *file, bool buffer)
Run-time initialization.
isc::log::Severity getSeverity(const std::string &sev_str)
Returns the isc::log::Severity value represented by the given string.
const std::string & getDefaultRootLoggerName()
Returns the default ('kea') root logger name.
const int MAX_DEBUG_LEVEL
int keaLoggerDbglevel(int defdbglevel)
Obtains logging debug level from KEA_LOGGER_DBGLEVEL.
void setDefaultLoggingOutput(bool verbose)
Reset root logger characteristics.
const int MIN_DEBUG_LEVEL
Minimum/maximum debug levels.
Severity
Severity Levels.
isc::log::Severity keaLoggerSeverity(isc::log::Severity defseverity)
Obtains logging severity from KEA_LOGGER_SEVERITY.
Defines the logger used by the top-level component of kea-lfc.