#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/hosts_log.h>
+#include <log/logger_support.h>
#ifdef HAVE_MYSQL
#include <dhcpsrv/mysql_host_data_source.h>
if ((*it)->getType() != db_type) {
continue;
}
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
+ LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
.arg(db_type);
sources.erase(it);
return (true);
bool
HostDataSourceFactory::registerFactory(const string& db_type,
- const Factory& factory) {
+ const Factory& factory,
+ bool no_log) {
if (map_.count(db_type)) {
return (false);
}
map_.insert(pair<string, Factory>(db_type, factory));
- // As registerFactory can be called before logging is established
- // remove temporary this until a better solution is found.
-#if 0
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
- .arg(db_type);
-#endif
+
+ // We are dealing here with static logger initialization fiasco.
+ // registerFactory may be called from constructors of static global
+ // objects for built in backends. The logging is not initialized yet,
+ // so the LOG_DEBUG would throw.
+ if (!no_log) {
+ LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
+ .arg(db_type);
+ }
return (true);
}
bool
-HostDataSourceFactory::deregisterFactory(const string& db_type) {
+HostDataSourceFactory::deregisterFactory(const string& db_type, bool no_log) {
auto index = map_.find(db_type);
if (index != map_.end()) {
map_.erase(index);
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_DEREGISTER)
- .arg(db_type);
+ if (!no_log) {
+ LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE,
+ HOSTS_BACKEND_DEREGISTER)
+ .arg(db_type);
+ }
return (true);
} else {
return (false);
}
}
+void
+HostDataSourceFactory::printRegistered() {
+ std::stringstream txt;
+
+ for (auto x : map_) {
+ txt << x.first << " ";
+ }
+
+ LOG_INFO(hosts_logger, HOSTS_BACKENDS_REGISTERED).arg(txt.str());
+}
+
} // namespace dhcp
} // namespace isc
struct MySqlHostDataSourceInit {
// Constructor registers
MySqlHostDataSourceInit() {
- HostDataSourceFactory::registerFactory("mysql", factory);
+ HostDataSourceFactory::registerFactory("mysql", factory, true);
}
// Destructor deregisters
~MySqlHostDataSourceInit() {
- HostDataSourceFactory::deregisterFactory("mysql");
+ HostDataSourceFactory::deregisterFactory("mysql", true);
}
// Factory class method
static HostDataSourcePtr
factory(const DatabaseConnection::ParameterMap& parameters) {
- LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_HOST_DB)
+ LOG_INFO(hosts_logger, DHCPSRV_MYSQL_HOST_DB)
.arg(DatabaseConnection::redactedAccessString(parameters));
return (HostDataSourcePtr(new MySqlHostDataSource(parameters)));
}
struct PgSqlHostDataSourceInit {
// Constructor registers
PgSqlHostDataSourceInit() {
- HostDataSourceFactory::registerFactory("postgresql", factory);
+ HostDataSourceFactory::registerFactory("postgresql", factory, true);
}
// Destructor deregisters
~PgSqlHostDataSourceInit() {
- HostDataSourceFactory::deregisterFactory("postgresql");
+ HostDataSourceFactory::deregisterFactory("postgresql", true);
}
// Factory class method
static HostDataSourcePtr
factory(const DatabaseConnection::ParameterMap& parameters) {
- LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_HOST_DB)
+ LOG_INFO(hosts_logger, DHCPSRV_PGSQL_HOST_DB)
.arg(DatabaseConnection::redactedAccessString(parameters));
return (HostDataSourcePtr(new PgSqlHostDataSource(parameters)));
}
struct CqlHostDataSourceInit {
// Constructor registers
CqlHostDataSourceInit() {
- HostDataSourceFactory::registerFactory("cql", factory);
+ HostDataSourceFactory::registerFactory("cql", factory, true);
}
// Destructor deregisters
~CqlHostDataSourceInit() {
- HostDataSourceFactory::deregisterFactory("cql");
+ HostDataSourceFactory::deregisterFactory("cql", true);
}
// Factory class method
#endif
} // end of anonymous namespace
-
#include <boost/function.hpp>
#include <string>
+#include <vector>
#include <map>
namespace isc {
/// @brief Register a host data source factory
///
/// Associate the factory to a database type in the map.
+ /// The no_log is to avoid logging before the logger is initialized
+ /// as when called at global object initialization.
///
/// @param db_type database type
/// @param factory host data source factory
+ /// @param no_log do not log (default false)
/// @return true if the factory was successfully added to the map, false
/// if it already exists.
static bool registerFactory(const std::string& db_type,
- const Factory& factory);
+ const Factory& factory, bool no_log = false);
/// @brief Deregister a host data source factory
///
/// Disassociate the factory to a database type in the map.
+ /// The no_log is to avoid logging during global object deinitialization.
///
/// @param db_type database type
+ /// @param no_log do not log (default false)
/// @return true if the factory was successfully removed from the map,
/// false if it was not found.
- static bool deregisterFactory(const std::string& db_type);
+ static bool deregisterFactory(const std::string& db_type,
+ bool no_log = false);
+
+ /// @brief Prints out all registered backends.
+ ///
+ /// We need a dedicated method for this, because we sometimes can't log
+ /// the backend type when doing early initialization for backends
+ /// initialized statically.
+ static void printRegistered();
private:
/// @brief Factory map