|
@@ -12,7 +12,6 @@
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// PERFORMANCE OF THIS SOFTWARE
|
|
// PERFORMANCE OF THIS SOFTWARE
|
|
|
|
|
|
-#include <iostream>
|
|
|
|
#include <iomanip>
|
|
#include <iomanip>
|
|
#include <algorithm>
|
|
#include <algorithm>
|
|
|
|
|
|
@@ -23,10 +22,10 @@
|
|
|
|
|
|
#include <log4cplus/configurator.h>
|
|
#include <log4cplus/configurator.h>
|
|
|
|
|
|
-#include <log/debug_levels.h>
|
|
|
|
#include <log/root_logger_name.h>
|
|
#include <log/root_logger_name.h>
|
|
#include <log/logger.h>
|
|
#include <log/logger.h>
|
|
-#include <log/logger_levels.h>
|
|
|
|
|
|
+#include <log/logger_level.h>
|
|
|
|
+#include <log/logger_level_impl.h>
|
|
#include <log/logger_impl.h>
|
|
#include <log/logger_impl.h>
|
|
#include <log/message_dictionary.h>
|
|
#include <log/message_dictionary.h>
|
|
#include <log/message_types.h>
|
|
#include <log/message_types.h>
|
|
@@ -35,6 +34,7 @@
|
|
#include <util/strutil.h>
|
|
#include <util/strutil.h>
|
|
|
|
|
|
using namespace std;
|
|
using namespace std;
|
|
|
|
+using namespace log4cplus;
|
|
|
|
|
|
namespace isc {
|
|
namespace isc {
|
|
namespace log {
|
|
namespace log {
|
|
@@ -45,21 +45,24 @@ namespace log {
|
|
// Constructor
|
|
// Constructor
|
|
LoggerImpl::LoggerImpl(const std::string& name, bool)
|
|
LoggerImpl::LoggerImpl(const std::string& name, bool)
|
|
{
|
|
{
|
|
|
|
+ // Initialize log4cplus if not already done
|
|
|
|
+ initLog4cplus();
|
|
|
|
+
|
|
// Are we the root logger?
|
|
// Are we the root logger?
|
|
if (name == getRootLoggerName()) {
|
|
if (name == getRootLoggerName()) {
|
|
is_root_ = true;
|
|
is_root_ = true;
|
|
name_ = name;
|
|
name_ = name;
|
|
|
|
+ logger_ = log4cplus::Logger::getRoot();
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
is_root_ = false;
|
|
is_root_ = false;
|
|
name_ = getRootLoggerName() + "." + name;
|
|
name_ = getRootLoggerName() + "." + name;
|
|
|
|
+ logger_ = log4cplus::Logger::getInstance(name_);
|
|
}
|
|
}
|
|
- fmt_name_ = std::string("[") + name_ + std::string("] ");
|
|
|
|
|
|
|
|
- // Initialize log4cplus if not already done
|
|
|
|
- initLog4cplus();
|
|
|
|
-
|
|
|
|
- // Return existing instance of logger, creating it if it does not exist.
|
|
|
|
- logger_ = log4cplus::Logger::getInstance(name_);
|
|
|
|
|
|
+ // Create a formatted name for use in messages (speeds up formatting if
|
|
|
|
+ // we do it now.)
|
|
|
|
+ fmt_name_ = std::string("[") + name_ + std::string("] ");
|
|
}
|
|
}
|
|
|
|
|
|
// Destructor. (Here because of virtual declaration.)
|
|
// Destructor. (Here because of virtual declaration.)
|
|
@@ -68,49 +71,44 @@ LoggerImpl::~LoggerImpl() {
|
|
}
|
|
}
|
|
|
|
|
|
// Set the severity for logging.
|
|
// Set the severity for logging.
|
|
-// TODO IGNORE DEBUG LEVEL FOR NOW
|
|
|
|
-
|
|
|
|
void
|
|
void
|
|
-LoggerImpl::setSeverity(isc::log::Severity severity, int /*dbglevel*/) {
|
|
|
|
-
|
|
|
|
- // Silently coerce the debug level into the valid range of 0 to 99
|
|
|
|
-
|
|
|
|
- //int debug_level = max(MIN_DEBUG_LEVEL, min(MAX_DEBUG_LEVEL, dbglevel));
|
|
|
|
- logger_.setLogLevel(convertFromBindSeverity(severity));
|
|
|
|
|
|
+LoggerImpl::setSeverity(isc::log::Severity severity, int dbglevel) {
|
|
|
|
+ isc::log::Level level(severity, dbglevel);
|
|
|
|
+ logger_.setLogLevel(LoggerLevelImpl::convertFromBindLevel(level));
|
|
}
|
|
}
|
|
|
|
|
|
// Return severity level
|
|
// Return severity level
|
|
-
|
|
|
|
isc::log::Severity
|
|
isc::log::Severity
|
|
LoggerImpl::getSeverity() {
|
|
LoggerImpl::getSeverity() {
|
|
- return convertToBindSeverity(logger_.getLogLevel());
|
|
|
|
|
|
+ isc::log::Level level =
|
|
|
|
+ LoggerLevelImpl::convertToBindLevel(logger_.getLogLevel());
|
|
|
|
+ return level.severity;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Return current debug level (only valid if current severity level is DEBUG).
|
|
|
|
+int
|
|
|
|
+LoggerImpl::getDebugLevel() {
|
|
|
|
+ isc::log::Level level =
|
|
|
|
+ LoggerLevelImpl::convertToBindLevel(logger_.getLogLevel());
|
|
|
|
+ return level.dbglevel;
|
|
}
|
|
}
|
|
|
|
|
|
// Get effective severity. Either the current severity or, if not set, the
|
|
// Get effective severity. Either the current severity or, if not set, the
|
|
// severity of the root level.
|
|
// severity of the root level.
|
|
-
|
|
|
|
isc::log::Severity
|
|
isc::log::Severity
|
|
LoggerImpl::getEffectiveSeverity() {
|
|
LoggerImpl::getEffectiveSeverity() {
|
|
- return convertToBindSeverity(logger_.getChainedLogLevel());
|
|
|
|
|
|
+ isc::log::Level level =
|
|
|
|
+ LoggerLevelImpl::convertToBindLevel(logger_.getChainedLogLevel());
|
|
|
|
+ return level.severity;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-// Get the debug level. This returns 0 unless the severity is DEBUG.
|
|
|
|
-// TODO: DEBUG LEVEL IGNORED FOR NOW
|
|
|
|
-
|
|
|
|
|
|
+// Return effective debug level (only valid if current effective severity level
|
|
|
|
+// is DEBUG).
|
|
int
|
|
int
|
|
-LoggerImpl::getDebugLevel() {
|
|
|
|
- return (0);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// The code for isXxxEnabled is quite simple and is in the header. The only
|
|
|
|
-// exception is isDebugEnabled() where we have the complication of the debug
|
|
|
|
-// levels.
|
|
|
|
-// TODO: DEBUG LEVEL IGNORED FOR NOW
|
|
|
|
-
|
|
|
|
-bool
|
|
|
|
-LoggerImpl::isDebugEnabled(int dbglevel) {
|
|
|
|
- return logger_.isEnabledFor(log4cplus::DEBUG_LOG_LEVEL);
|
|
|
|
|
|
+LoggerImpl::getEffectiveDebugLevel() {
|
|
|
|
+ isc::log::Level level =
|
|
|
|
+ LoggerLevelImpl::convertToBindLevel(logger_.getChainedLogLevel());
|
|
|
|
+ return level.dbglevel;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -145,68 +143,6 @@ LoggerImpl::outputRaw(const Severity& severity, const string& message) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// Convert levels - from BIND 10 level to log4cplus level.
|
|
|
|
-// Namespaces explicitly used to clarify what level we are talking about
|
|
|
|
-log4cplus::LogLevel
|
|
|
|
-LoggerImpl::convertFromBindSeverity(const isc::log::Severity& inlevel) {
|
|
|
|
-
|
|
|
|
- // BIND 10 logging levels are small integers so we can do a table lookup
|
|
|
|
- static const log4cplus::LogLevel level[] = {
|
|
|
|
- log4cplus::NOT_SET_LOG_LEVEL,
|
|
|
|
- log4cplus::DEBUG_LOG_LEVEL,
|
|
|
|
- log4cplus::INFO_LOG_LEVEL,
|
|
|
|
- log4cplus::WARN_LOG_LEVEL,
|
|
|
|
- log4cplus::ERROR_LOG_LEVEL,
|
|
|
|
- log4cplus::FATAL_LOG_LEVEL,
|
|
|
|
- log4cplus::OFF_LOG_LEVEL
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // ... with compile-time checks to ensure that table indexes are correct.
|
|
|
|
- BOOST_STATIC_ASSERT(static_cast<int>(isc::log::DEFAULT) == 0);
|
|
|
|
- BOOST_STATIC_ASSERT(static_cast<int>(isc::log::DEBUG) == 1);
|
|
|
|
- BOOST_STATIC_ASSERT(static_cast<int>(isc::log::INFO) == 2);
|
|
|
|
- BOOST_STATIC_ASSERT(static_cast<int>(isc::log::WARN) == 3);
|
|
|
|
- BOOST_STATIC_ASSERT(static_cast<int>(isc::log::ERROR) == 4);
|
|
|
|
- BOOST_STATIC_ASSERT(static_cast<int>(isc::log::FATAL) == 5);
|
|
|
|
- BOOST_STATIC_ASSERT(static_cast<int>(isc::log::NONE) == 6);
|
|
|
|
-
|
|
|
|
- // No need to check that the iundex is out of range. Setting the type of
|
|
|
|
- // the argument to isc::log::Severity ensures that it must be one of the
|
|
|
|
- // Severity enum members - conversion of a numeric value to an enum is not
|
|
|
|
- // permitted.
|
|
|
|
- return (level[inlevel]);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// Convert levels - from log4plus level to BIND 10 level
|
|
|
|
-// Namespaces explicitly used to clarify what level we are talking about
|
|
|
|
-isc::log::Severity
|
|
|
|
-LoggerImpl::convertToBindSeverity(const log4cplus::LogLevel& inlevel) {
|
|
|
|
-
|
|
|
|
- // Not easy to do a table lookup as the numerical values of log4cplus levels
|
|
|
|
- // are quite high.
|
|
|
|
- switch (inlevel) {
|
|
|
|
- case log4cplus::NOT_SET_LOG_LEVEL:
|
|
|
|
- return (isc::log::DEFAULT);
|
|
|
|
-
|
|
|
|
- case log4cplus::DEBUG_LOG_LEVEL:
|
|
|
|
- return (isc::log::DEBUG);
|
|
|
|
-
|
|
|
|
- case log4cplus::INFO_LOG_LEVEL:
|
|
|
|
- return (isc::log::INFO);
|
|
|
|
-
|
|
|
|
- case log4cplus::WARN_LOG_LEVEL:
|
|
|
|
- return (isc::log::WARN);
|
|
|
|
-
|
|
|
|
- case log4cplus::ERROR_LOG_LEVEL:
|
|
|
|
- return (isc::log::ERROR);
|
|
|
|
-
|
|
|
|
- case log4cplus::FATAL_LOG_LEVEL:
|
|
|
|
- return (isc::log::FATAL);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return (isc::log::NONE);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// One-time initialization of log4cplus
|
|
// One-time initialization of log4cplus
|
|
|
|
|
|
|
|
|
|
@@ -215,8 +151,14 @@ LoggerImpl::initLog4cplus() {
|
|
static bool not_initialized = true;
|
|
static bool not_initialized = true;
|
|
|
|
|
|
if (not_initialized) {
|
|
if (not_initialized) {
|
|
|
|
+ // Set up basic configurator
|
|
log4cplus::BasicConfigurator config;
|
|
log4cplus::BasicConfigurator config;
|
|
config.configure();
|
|
config.configure();
|
|
|
|
+
|
|
|
|
+ // Add additional debug levels
|
|
|
|
+ LoggerLevelImpl::init();
|
|
|
|
+
|
|
|
|
+ // All done.
|
|
not_initialized = false;
|
|
not_initialized = false;
|
|
}
|
|
}
|
|
}
|
|
}
|