Commit a98a90d8 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac747] Logging of portconfig

parent 421d1991
......@@ -19,11 +19,17 @@ endif
lib_LTLIBRARIES = libserver_common.la
libserver_common_la_SOURCES = portconfig.h portconfig.cc
libserver_common_la_SOURCES += keyring.h keyring.cc
libserver_common_la_SOURCES += logger.h logger.cc
nodist_libserver_common_la_SOURCES = server_common_messages.h
nodist_libserver_common_la_SOURCES += server_common_messages.cc
libserver_common_la_LIBADD = $(top_builddir)/src/lib/exceptions/libexceptions.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/cc/libcc.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/config/libcfgclient.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/log/liblog.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/dns/libdns++.la
BUILT_SOURCES = server_common_messages.h server_common_messages.cc
server_common_messages.h server_common_messages.cc: server_common_messages.mes
$(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/lib/server_common/server_common_messages.mes
CLEANFILES = *.gcno *.gcda
CLEANFILES = *.gcno *.gcda messagedef.h messagedef.cc
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <server_common/logger.h>
namespace isc {
namespace server_common {
isc::log::Logger logger("server_common");
}
}
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef __SERVER_COMMON_LOGGER_H
#define __SERVER_COMMON_LOGGER_H
#include <log/macros.h>
#include <server_common/server_common_messages.h>
/// \file logger.h
/// \brief Server Common library global logger
///
/// This holds the logger for the server common library. It is a private header
/// and should not be included in any publicly used header, only in local
/// cc files.
namespace isc {
namespace server_common {
/// \brief The logger for this library
extern isc::log::Logger logger;
enum {
/// \brief Trace basic operations
DBG_TRACE_BASIC = 10,
/// \brief Print also values used
DBG_TRACE_VALUES = 40
};
}
}
#endif
......@@ -13,10 +13,10 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <server_common/portconfig.h>
#include <server_common/logger.h>
#include <asiolink/io_address.h>
#include <asiodns/dns_service.h>
#include <log/dummylog.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
......@@ -25,7 +25,6 @@ using namespace std;
using namespace isc::data;
using namespace isc::asiolink;
using namespace isc::asiodns;
using isc::log::dlog;
namespace isc {
namespace server_common {
......@@ -43,6 +42,8 @@ parseAddresses(isc::data::ConstElementPtr addresses,
ConstElementPtr addr(addrPair->get("address"));
ConstElementPtr port(addrPair->get("port"));
if (!addr || ! port) {
LOG_ERROR(logger, SRV_COMMON_ADDRESS_MISSING).
arg(addrPair->str());
isc_throw(BadValue, "Address must contain both the IP"
"address and port");
}
......@@ -50,6 +51,8 @@ parseAddresses(isc::data::ConstElementPtr addresses,
IOAddress(addr->stringValue());
if (port->intValue() < 0 ||
port->intValue() > 0xffff) {
LOG_ERROR(logger, SRV_COMMON_PORT_RANGE).
arg(port->intValue()).arg(addrPair->str());
isc_throw(BadValue, "Bad port value (" <<
port->intValue() << ")");
}
......@@ -57,11 +60,14 @@ parseAddresses(isc::data::ConstElementPtr addresses,
port->intValue()));
}
catch (const TypeError &e) { // Better error message
LOG_ERROR(logger, SRV_COMMON_ADDRESS_TYPE).
arg(addrPair->str());
isc_throw(TypeError,
"Address must be a string and port an integer");
}
}
} else if (addresses->getType() != Element::null) {
LOG_ERROR(logger, SRV_COMMON_ADDRESSES_NOT_LIST);
isc_throw(TypeError, elemName + " config element must be a list");
}
}
......@@ -86,10 +92,10 @@ installListenAddresses(const AddressList& newAddresses,
isc::asiodns::DNSService& service)
{
try {
dlog("Setting listen addresses:");
LOG_DEBUG(logger, DBG_TRACE_BASIC, SRV_COMMON_SET_LISTEN);
BOOST_FOREACH(const AddressPair& addr, newAddresses) {
dlog(" " + addr.first + ":" +
boost::lexical_cast<string>(addr.second));
LOG_DEBUG(logger, DBG_TRACE_VALUES, SRV_COMMON_ADDRESS_VALUE).
arg(addr.first).arg(addr.second);
}
setAddresses(service, newAddresses);
addressStore = newAddresses;
......@@ -108,13 +114,12 @@ installListenAddresses(const AddressList& newAddresses,
* user will get error info, command control can be used to set new
* address. So we just catch the exception without propagating outside
*/
dlog(string("Unable to set new address: ") + e.what(), true);
LOG_ERROR(logger, SRV_COMMON_ADDRESS_FAIL).arg(e);
try {
setAddresses(service, addressStore);
}
catch (const exception& e2) {
dlog("Unable to recover from error;", true);
dlog(string("Rollback failed with: ") + e2.what(), true);
LOG_FATAL(logger, SRV_COMMON_ADDRESS_UNRECOVERABLE).arg(e2);
}
//Anyway the new configure has problem, we need to notify configure
//manager the new configure doesn't work
......
# Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
$NAMESPACE isc::server_common
# \brief Messages for the server_common library
% SRV_COMMON_ADDRESS_MISSING Address specification is missing "address" or "port" element in %1
% SRV_COMMON_PORT_RANGE Port out of valid range (%1 in %2)
% SRV_COMMON_ADDRESS_TYPE Address specification type is invalid in %1
% SRV_COMMON_ADDRESSES_NOT_LIST The address and port specification is not a list
% SRV_COMMON_SET_LISTEN Setting addresses to listen to
% SRV_COMMON_ADDRESS_VALUE Address to set: %1#%2
% SRV_COMMON_ADDRESS_FAIL Failed to listen on addresses (%1)
% SRV_COMMON_ADDRESS_UNRECOVERABLE Failed to recover original addresses also (%2)
......@@ -16,6 +16,7 @@
#include <gtest/gtest.h>
#include <util/unittests/run_all.h>
#include <log/logger_support.h>
#include <dns/tests/unittest_util.h>
......@@ -23,5 +24,7 @@ int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
isc::log::initLogger();
return (isc::util::unittests::run_all());
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment