2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-03 15:35:17 +00:00

[2445] Make buffering optional, and enable in b10 components

This commit is contained in:
Jelte Jansen
2012-11-28 21:34:14 +01:00
parent bbefd6bc41
commit 9c4e97e7f8
20 changed files with 129 additions and 72 deletions

View File

@@ -147,7 +147,7 @@ main(int argc, char* argv[]) {
// Initialize logging. If verbose, we'll use maximum verbosity. // Initialize logging. If verbose, we'll use maximum verbosity.
isc::log::initLogger(AUTH_NAME, isc::log::initLogger(AUTH_NAME,
(verbose ? isc::log::DEBUG : isc::log::INFO), (verbose ? isc::log::DEBUG : isc::log::INFO),
isc::log::MAX_DEBUG_LEVEL, NULL); isc::log::MAX_DEBUG_LEVEL, NULL, true);
int ret = 0; int ret = 0;
@@ -256,7 +256,9 @@ main(int argc, char* argv[]) {
// If we haven't registered callback for data sources, this will be just // If we haven't registered callback for data sources, this will be just
// no-op. // no-op.
config_session->removeRemoteConfig("data_sources"); if (config_session) {
config_session->removeRemoteConfig("data_sources");
}
delete xfrin_session; delete xfrin_session;
delete config_session; delete config_session;

View File

@@ -76,7 +76,7 @@ import isc.bind10.socket_cache
import libutil_io_python import libutil_io_python
import tempfile import tempfile
isc.log.init("b10-boss") isc.log.init("b10-boss", buffer=True)
logger = isc.log.Logger("boss") logger = isc.log.Logger("boss")
# Pending system-wide debug level definitions, the ones we # Pending system-wide debug level definitions, the ones we

View File

@@ -27,7 +27,7 @@ import glob
import os.path import os.path
import imp import imp
import isc.log import isc.log
isc.log.init("b10-cfgmgr") isc.log.init("b10-cfgmgr", buffer=True)
from isc.config.cfgmgr import ConfigManager, ConfigManagerDataReadError, logger from isc.config.cfgmgr import ConfigManager, ConfigManagerDataReadError, logger
from isc.log_messages.cfgmgr_messages import * from isc.log_messages.cfgmgr_messages import *

View File

@@ -49,7 +49,7 @@ from hashlib import sha1
from isc.util import socketserver_mixin from isc.util import socketserver_mixin
from isc.log_messages.cmdctl_messages import * from isc.log_messages.cmdctl_messages import *
isc.log.init("b10-cmdctl") isc.log.init("b10-cmdctl", buffer=True)
logger = isc.log.Logger("cmdctl") logger = isc.log.Logger("cmdctl")
# Debug level for communication with BIND10 # Debug level for communication with BIND10

View File

@@ -45,7 +45,7 @@ import os.path
import signal import signal
import socket import socket
isc.log.init("b10-ddns") isc.log.init("b10-ddns", buffer=True)
logger = isc.log.Logger("ddns") logger = isc.log.Logger("ddns")
TRACE_BASIC = logger.DBGLVL_TRACE_BASIC TRACE_BASIC = logger.DBGLVL_TRACE_BASIC

View File

@@ -95,7 +95,7 @@ main(int argc, char* argv[]) {
// Initialize logging. If verbose, we'll use maximum verbosity. // Initialize logging. If verbose, we'll use maximum verbosity.
isc::log::initLogger(DHCP4_NAME, isc::log::initLogger(DHCP4_NAME,
(verbose_mode ? isc::log::DEBUG : isc::log::INFO), (verbose_mode ? isc::log::DEBUG : isc::log::INFO),
isc::log::MAX_DEBUG_LEVEL, NULL); isc::log::MAX_DEBUG_LEVEL, NULL, true);
LOG_INFO(dhcp4_logger, DHCP4_STARTING); LOG_INFO(dhcp4_logger, DHCP4_STARTING);
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_START_INFO) LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_START_INFO)
.arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no") .arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no")

View File

@@ -105,7 +105,7 @@ main(int argc, char* argv[]) {
// Initialize logging. If verbose, we'll use maximum verbosity. // Initialize logging. If verbose, we'll use maximum verbosity.
isc::log::initLogger(DHCP6_NAME, isc::log::initLogger(DHCP6_NAME,
(verbose_mode ? isc::log::DEBUG : isc::log::INFO), (verbose_mode ? isc::log::DEBUG : isc::log::INFO),
isc::log::MAX_DEBUG_LEVEL, NULL); isc::log::MAX_DEBUG_LEVEL, NULL, true);
LOG_INFO(dhcp6_logger, DHCP6_STARTING); LOG_INFO(dhcp6_logger, DHCP6_STARTING);
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_START_INFO) LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_START_INFO)
.arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no") .arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no")

View File

@@ -143,7 +143,7 @@ main(int argc, char* argv[]) {
// temporary initLogger() code. If verbose, we'll use maximum verbosity. // temporary initLogger() code. If verbose, we'll use maximum verbosity.
isc::log::initLogger(RESOLVER_NAME, isc::log::initLogger(RESOLVER_NAME,
(verbose ? isc::log::DEBUG : isc::log::INFO), (verbose ? isc::log::DEBUG : isc::log::INFO),
isc::log::MAX_DEBUG_LEVEL, NULL); isc::log::MAX_DEBUG_LEVEL, NULL, true);
// Print the starting message // Print the starting message
string cmdline = argv[0]; string cmdline = argv[0];

View File

@@ -31,7 +31,7 @@ import isc.util.process
import isc.log import isc.log
from isc.log_messages.stats_messages import * from isc.log_messages.stats_messages import *
isc.log.init("b10-stats") isc.log.init("b10-stats", buffer=True)
logger = isc.log.Logger("stats") logger = isc.log.Logger("stats")
# Some constants for debug levels. # Some constants for debug levels.
@@ -682,7 +682,7 @@ if __name__ == "__main__":
help="enable maximum debug logging") help="enable maximum debug logging")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if options.verbose: if options.verbose:
isc.log.init("b10-stats", "DEBUG", 99) isc.log.init("b10-stats", "DEBUG", 99, buffer=True)
stats = Stats() stats = Stats()
stats.start() stats.start()
except OptionValueError as ove: except OptionValueError as ove:

View File

@@ -39,7 +39,7 @@ import isc.util.process
import isc.log import isc.log
from isc.log_messages.stats_httpd_messages import * from isc.log_messages.stats_httpd_messages import *
isc.log.init("b10-stats-httpd") isc.log.init("b10-stats-httpd", buffer=True)
logger = isc.log.Logger("stats-httpd") logger = isc.log.Logger("stats-httpd")
# Some constants for debug levels. # Some constants for debug levels.
@@ -609,7 +609,7 @@ if __name__ == "__main__":
help="enable maximum debug logging") help="enable maximum debug logging")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if options.verbose: if options.verbose:
isc.log.init("b10-stats-httpd", "DEBUG", 99) isc.log.init("b10-stats-httpd", "DEBUG", 99, buffer=True)
stats_httpd = StatsHttpd() stats_httpd = StatsHttpd()
stats_httpd.start() stats_httpd.start()
except OptionValueError as ove: except OptionValueError as ove:

View File

@@ -36,7 +36,7 @@ from isc.xfrin.diff import Diff
from isc.server_common.auth_command import auth_loadzone_command from isc.server_common.auth_command import auth_loadzone_command
from isc.log_messages.xfrin_messages import * from isc.log_messages.xfrin_messages import *
isc.log.init("b10-xfrin") isc.log.init("b10-xfrin", buffer=True)
logger = isc.log.Logger("xfrin") logger = isc.log.Logger("xfrin")
# Pending system-wide debug level definitions, the ones we # Pending system-wide debug level definitions, the ones we

View File

@@ -38,7 +38,7 @@ import isc.server_common.tsig_keyring
from isc.log_messages.xfrout_messages import * from isc.log_messages.xfrout_messages import *
isc.log.init("b10-xfrout") isc.log.init("b10-xfrout", buffer=True)
logger = isc.log.Logger("xfrout") logger = isc.log.Logger("xfrout")
# Pending system-wide debug level definitions, the ones we # Pending system-wide debug level definitions, the ones we

View File

@@ -42,7 +42,7 @@ from isc.log_messages.zonemgr_messages import *
from isc.notify import notify_out from isc.notify import notify_out
# Initialize logging for called modules. # Initialize logging for called modules.
isc.log.init("b10-zonemgr") isc.log.init("b10-zonemgr", buffer=True)
logger = isc.log.Logger("zonemgr") logger = isc.log.Logger("zonemgr")
# Pending system-wide debug level definitions, the ones we # Pending system-wide debug level definitions, the ones we

View File

@@ -94,9 +94,8 @@ LoggerManager::processEnd() {
void void
LoggerManager::init(const std::string& root, isc::log::Severity severity, LoggerManager::init(const std::string& root, isc::log::Severity severity,
int dbglevel, const char* file) int dbglevel, const char* file, bool buffer)
{ {
// Load in the messages declared in the program and registered by // Load in the messages declared in the program and registered by
// statically-declared MessageInitializer objects. // statically-declared MessageInitializer objects.
MessageInitializer::loadDictionary(); MessageInitializer::loadDictionary();
@@ -115,7 +114,9 @@ LoggerManager::init(const std::string& root, isc::log::Severity severity,
// Initialize the implementation logging. After this point, some basic // Initialize the implementation logging. After this point, some basic
// logging has been set up and messages can be logged. // logging has been set up and messages can be logged.
LoggerManagerImpl::init(severity, dbglevel); // However, they will not appear until a logging specification has been
// processed (or the program exits), see TODO
LoggerManagerImpl::init(severity, dbglevel, buffer);
setLoggingInitialized(); setLoggingInitialized();
// Check if there were any duplicate message IDs in the default dictionary // Check if there were any duplicate message IDs in the default dictionary
@@ -188,9 +189,9 @@ LoggerManager::readLocalMessageFile(const char* file) {
// Reset logging to settings passed to init() // Reset logging to settings passed to init()
void void
LoggerManager::reset() { LoggerManager::reset(bool buffer) {
setRootLoggerName(initRootName()); setRootLoggerName(initRootName());
LoggerManagerImpl::reset(initSeverity(), initDebugLevel()); LoggerManagerImpl::reset(initSeverity(), initDebugLevel(), buffer);
} }
} // namespace log } // namespace log

View File

@@ -60,9 +60,7 @@ public:
void process(T start, T finish) { void process(T start, T finish) {
processInit(); processInit();
if (start == finish) { if (start == finish) {
// empty iterator; set defaults process();
const LoggerSpecification spec;
processSpecification(spec);
} else { } else {
for (T i = start; i != finish; ++i) { for (T i = start; i != finish; ++i) {
processSpecification(*i); processSpecification(*i);
@@ -82,6 +80,22 @@ public:
processEnd(); processEnd();
} }
/// \brief Process 'empty' specification
///
/// This will disable any existing output options, and set
/// the logging to go to the built-in default (stdout).
/// If the logger has been initialized with buffering enabled,
/// all log messages up to now shall be printed to stdout.
///
/// This is mainly useful in scenarios where buffering is needed,
/// but it turns out there are no logging specifications to
/// handle.
void process() {
// empty iterator; set defaults
const LoggerSpecification spec;
processSpecification(spec);
}
/// \brief Run-Time Initialization /// \brief Run-Time Initialization
/// ///
/// Performs run-time initialization of the logger system, in particular /// Performs run-time initialization of the logger system, in particular
@@ -97,14 +111,22 @@ public:
/// \param dbglevel Debug severity (ignored if "severity" is not "DEBUG") /// \param dbglevel Debug severity (ignored if "severity" is not "DEBUG")
/// \param file Name of the local message file. This must be NULL if there /// \param file Name of the local message file. This must be NULL if there
/// is no local message file. /// is no local message file.
/// \param buffer If true, all log messages will be buffered until one of
/// the \c process() methods is called. If false, initial logging
/// shall go to the default output (i.e. stdout)
static void init(const std::string& root, static void init(const std::string& root,
isc::log::Severity severity = isc::log::INFO, isc::log::Severity severity = isc::log::INFO,
int dbglevel = 0, const char* file = NULL); int dbglevel = 0, const char* file = NULL,
bool buffer = false);
/// \brief Reset logging /// \brief Reset logging
/// ///
/// Resets logging to whatever was set in the call to init(). /// Resets logging to whatever was set in the call to init().
static void reset(); ///
/// \param buffer If true, all log messages will be buffered until one of
/// the \c process() methods is called. If false, initial logging
/// shall go to the default output (i.e. stdout)
static void reset(bool buffer = false);
/// \brief Read local message file /// \brief Read local message file
/// ///

View File

@@ -65,6 +65,9 @@ public:
// be a good idea. // be a good idea.
for (size_t i = 0; i < stored_.size(); ++i) { for (size_t i = 0; i < stored_.size(); ++i) {
std::cout << stored_.at(i).getMessage() << std::endl; std::cout << stored_.at(i).getMessage() << std::endl;
log4cplus::Logger logger = log4cplus::Logger::getInstance(stored_.at(i).getLoggerName());
logger.log(stored_.at(i).getLogLevel(), stored_.at(i).getMessage());
} }
stored_.clear(); stored_.clear();
} }
@@ -241,7 +244,9 @@ LoggerManagerImpl::createSyslogAppender(log4cplus::Logger& logger,
// One-time initialization of the log4cplus system // One-time initialization of the log4cplus system
void void
LoggerManagerImpl::init(isc::log::Severity severity, int dbglevel) { LoggerManagerImpl::init(isc::log::Severity severity, int dbglevel,
bool buffer)
{
// Set up basic configurator. This attaches a ConsoleAppender to the // Set up basic configurator. This attaches a ConsoleAppender to the
// root logger with suitable output. This is used until we we have // root logger with suitable output. This is used until we we have
// actually read the logging configuration, in which case the output // actually read the logging configuration, in which case the output
@@ -252,21 +257,23 @@ LoggerManagerImpl::init(isc::log::Severity severity, int dbglevel) {
// Add the additional debug levels // Add the additional debug levels
LoggerLevelImpl::init(); LoggerLevelImpl::init();
reset(severity, dbglevel); reset(severity, dbglevel, buffer);
} }
// Reset logging to default configuration. This closes all appenders // Reset logging to default configuration. This closes all appenders
// and resets the root logger to output INFO messages to the console. // and resets the root logger to output INFO messages to the console.
// It is principally used in testing. // It is principally used in testing.
void void
LoggerManagerImpl::reset(isc::log::Severity severity, int dbglevel) { LoggerManagerImpl::reset(isc::log::Severity severity, int dbglevel,
bool buffer)
{
// Initialize the root logger // Initialize the root logger
initRootLogger(severity, dbglevel); initRootLogger(severity, dbglevel, buffer);
} }
// Initialize the root logger // Initialize the root logger
void LoggerManagerImpl::initRootLogger(isc::log::Severity severity, void LoggerManagerImpl::initRootLogger(isc::log::Severity severity,
int dbglevel) int dbglevel, bool buffer)
{ {
log4cplus::Logger::getDefaultHierarchy().resetConfiguration(); log4cplus::Logger::getDefaultHierarchy().resetConfiguration();
@@ -281,14 +288,12 @@ void LoggerManagerImpl::initRootLogger(isc::log::Severity severity,
b10root.setLogLevel(LoggerLevelImpl::convertFromBindLevel( b10root.setLogLevel(LoggerLevelImpl::convertFromBindLevel(
Level(severity, dbglevel))); Level(severity, dbglevel)));
// Set the BIND 10 root to use a console logger. if (buffer) {
//OutputOption opt; createBufferAppender(b10root);
//createConsoleAppender(b10root, opt); } else {
createBufferAppender(b10root); OutputOption opt;
//if (!buffer_appender_) { createConsoleAppender(b10root, opt);
// buffer_appender_ = new BufferAppender(logger); }
// b10_root.addAppender(buffer_appender_);
//}
} }
void LoggerManagerImpl::setConsoleAppenderLayout( void LoggerManagerImpl::setConsoleAppenderLayout(

View File

@@ -88,8 +88,11 @@ public:
/// ///
/// \param severity Severity to be associated with this logger /// \param severity Severity to be associated with this logger
/// \param dbglevel Debug level associated with the root logger /// \param dbglevel Debug level associated with the root logger
/// \param buffer If true, all log messages will be buffered until one of
/// the \c process() methods is called. If false, initial logging
/// shall go to the default output (i.e. stdout)
static void init(isc::log::Severity severity = isc::log::INFO, static void init(isc::log::Severity severity = isc::log::INFO,
int dbglevel = 0); int dbglevel = 0, bool buffer = false);
/// \brief Reset logging /// \brief Reset logging
/// ///
@@ -98,8 +101,11 @@ public:
/// ///
/// \param severity Severity to be associated with this logger /// \param severity Severity to be associated with this logger
/// \param dbglevel Debug level associated with the root logger /// \param dbglevel Debug level associated with the root logger
/// \param buffer If true, all log messages will be buffered until one of
/// the \c process() methods is called. If false, initial logging
/// shall go to the default output (i.e. stdout)
static void reset(isc::log::Severity severity = isc::log::INFO, static void reset(isc::log::Severity severity = isc::log::INFO,
int dbglevel = 0); int dbglevel = 0, bool buffer = false);
private: private:
/// \brief Create console appender /// \brief Create console appender
@@ -142,8 +148,11 @@ private:
/// ///
/// \param severity Severity of messages that the logger should output. /// \param severity Severity of messages that the logger should output.
/// \param dbglevel Debug level if severity = DEBUG /// \param dbglevel Debug level if severity = DEBUG
/// \param buffer If true, all log messages will be buffered until one of
/// the \c process() methods is called. If false, initial logging
/// shall go to the default output (i.e. stdout)
static void initRootLogger(isc::log::Severity severity = isc::log::INFO, static void initRootLogger(isc::log::Severity severity = isc::log::INFO,
int dbglevel = 0); int dbglevel = 0, bool buffer = false);
/// \brief Set layout for console appender /// \brief Set layout for console appender
/// ///

View File

@@ -46,8 +46,8 @@ setLoggingInitialized(bool state) {
void void
initLogger(const string& root, isc::log::Severity severity, int dbglevel, initLogger(const string& root, isc::log::Severity severity, int dbglevel,
const char* file) { const char* file, bool buffer) {
LoggerManager::init(root, severity, dbglevel, file); LoggerManager::init(root, severity, dbglevel, file, buffer);
} }
} // namespace log } // namespace log

View File

@@ -61,9 +61,13 @@ void setLoggingInitialized(bool state = true);
/// \param severity Severity at which to log /// \param severity Severity at which to log
/// \param dbglevel Debug severity (ignored if "severity" is not "DEBUG") /// \param dbglevel Debug severity (ignored if "severity" is not "DEBUG")
/// \param file Name of the local message file. /// \param file Name of the local message file.
/// \param buffer If true, all log messages will be buffered until one of
/// the \c process() methods is called. If false, initial logging
/// shall go to the default output (i.e. stdout)
void initLogger(const std::string& root, void initLogger(const std::string& root,
isc::log::Severity severity = isc::log::INFO, isc::log::Severity severity = isc::log::INFO,
int dbglevel = 0, const char* file = NULL); int dbglevel = 0, const char* file = NULL,
bool buffer = false);
} // namespace log } // namespace log
} // namespace isc } // namespace isc

View File

@@ -166,17 +166,24 @@ reset(PyObject*, PyObject*) {
} }
PyObject* PyObject*
init(PyObject*, PyObject* args) { init(PyObject*, PyObject* args, PyObject* arg_keywords) {
const char* root; const char* root;
const char* file(NULL); const char* file(NULL);
const char* severity("INFO"); const char* severity("INFO");
bool buffer = false;
int dbglevel(0); int dbglevel(0);
if (!PyArg_ParseTuple(args, "s|siz", &root, &severity, &dbglevel, &file)) { const char* keywords[] = { "name", "severity", "debuglevel", "file",
"buffer", NULL};
if (!PyArg_ParseTupleAndKeywords(args, arg_keywords, "s|sizb",
const_cast<char**>(keywords), &root,
&severity, &dbglevel, &file,
&buffer)) {
return (NULL); return (NULL);
} }
try { try {
LoggerManager::init(root, getSeverity(severity), dbglevel, file); LoggerManager::init(root, getSeverity(severity), dbglevel, file,
buffer);
} }
catch (const std::exception& e) { catch (const std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what()); PyErr_SetString(PyExc_RuntimeError, e.what());
@@ -266,12 +273,19 @@ PyMethodDef methods[] = {
"need to call it. It returns None if the message does not exist."}, "need to call it. It returns None if the message does not exist."},
{"reset", reset, METH_NOARGS, {"reset", reset, METH_NOARGS,
"Reset all logging. For testing purposes only, do not use."}, "Reset all logging. For testing purposes only, do not use."},
{"init", init, METH_VARARGS, {"init", reinterpret_cast<PyCFunction>(init), METH_VARARGS | METH_KEYWORDS,
"Run-time initialization. You need to call this before you do any " "Run-time initialization. You need to call this before you do any "
"logging, to configure the root logger name. You may also provide " "logging, to configure the root logger name. You may also provide "
"logging severity (one of 'DEBUG', 'INFO', 'WARN', 'ERROR' or " "Arguments:\n"
"'FATAL'), a debug level (integer in the range 0-99) and a file name " "name: root logger name\n"
"of a dictionary with message text translations."}, "severity (optional): one of 'DEBUG', 'INFO', 'WARN', 'ERROR' or "
"'FATAL')\n"
"debuglevel (optional): a debug level (integer in the range 0-99) "
"file (optional): a file name of a dictionary with message text "
"translations\n"
"buffer (optional), boolean, when True, causes all log messages "
"to be stored internally until log_config_update is called, at "
"which pointed they shall be logged."},
{"resetUnitTestRootLogger", resetUnitTestRootLogger, METH_VARARGS, {"resetUnitTestRootLogger", resetUnitTestRootLogger, METH_VARARGS,
"Resets the configuration of the root logger to that set by the " "Resets the configuration of the root logger to that set by the "
"B10_XXX environment variables. It is aimed at unit tests, where " "B10_XXX environment variables. It is aimed at unit tests, where "