Kea  1.5.0
db_log.cc
Go to the documentation of this file.
1 // Copyright (C) 2018 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 
8 
9 #include <config.h>
10 
11 #include <exceptions/exceptions.h>
12 #include <database/db_log.h>
13 #include <database/db_messages.h>
14 
15 using namespace isc::log;
16 
17 namespace isc {
18 namespace db {
19 
22 
25  { DB_INVALID_ACCESS, DATABASE_INVALID_ACCESS },
26 
27  { PGSQL_DEALLOC_ERROR, DATABASE_PGSQL_DEALLOC_ERROR },
28  { PGSQL_FATAL_ERROR, DATABASE_PGSQL_FATAL_ERROR },
29  { PGSQL_START_TRANSACTION, DATABASE_PGSQL_START_TRANSACTION },
30  { PGSQL_COMMIT, DATABASE_PGSQL_COMMIT },
31  { PGSQL_ROLLBACK, DATABASE_PGSQL_ROLLBACK },
32 
33  { MYSQL_FATAL_ERROR, DATABASE_MYSQL_FATAL_ERROR },
34  { MYSQL_START_TRANSACTION, DATABASE_MYSQL_START_TRANSACTION },
35  { MYSQL_COMMIT, DATABASE_MYSQL_COMMIT },
36  { MYSQL_ROLLBACK, DATABASE_MYSQL_ROLLBACK },
37 
38  { CQL_DEALLOC_ERROR, DATABASE_CQL_DEALLOC_ERROR },
40  DATABASE_CQL_CONNECTION_BEGIN_TRANSACTION },
41  { CQL_CONNECTION_COMMIT, DATABASE_CQL_CONNECTION_COMMIT },
42  { CQL_CONNECTION_ROLLBACK, DATABASE_CQL_CONNECTION_ROLLBACK }
43 };
44 
45 
47 
49 
51 
52 
53 const MessageID&
54 DbLogger::translateMessage(const DbMessageID& id) const {
55  try {
56  return (map_.at(id));
57  } catch (const std::out_of_range&) {
58  isc_throw(isc::Unexpected, "can't map message: " << id);
59  }
60 }
61 
63  if (db_logger_stack.empty()) {
64  isc_throw(isc::Unexpected, "database logger stack is empty");
65  }
66 }
67 
68 } // namespace db
69 } // namespace isc
We want to reuse the database backend connection and exchange code for other uses,...
Logger Class.
Definition: log/logger.h:143
DbMessageID
Database messages.
Definition: db_log.h:51
const DbLogger::MessageMap db_message_map
Map of translated messages.
Definition: db_log.cc:24
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::map< DbMessageID, isc::log::MessageID > MessageMap
Translation map type.
Definition: db_log.h:77
A generic exception that is thrown when an unexpected error condition occurs.
std::list< DbLogger > DbLoggerStack
Database logger stack.
Definition: db_log.h:102
DbLoggerStack db_logger_stack
Global database logger stack (initialized to dhcpsrv logger)
Definition: db_log.cc:50
const int DB_DBG_TRACE_DETAIL
Database logging levels.
Definition: db_log.h:40
Defines the logger used by the top-level component of kea-dhcp-ddns.
void checkDbLoggerStack()
Check database logger stack.
Definition: db_log.cc:62
DbLogger db_logger_translator(database_logger, db_message_map)
Database logger translator.
Definition: db_log.h:157
isc::log::Logger database_logger("database")
Common database library logger.
Definition: db_log.h:45
const int DBGLVL_TRACE_DETAIL
Trace detailed operations.
Definition: log_dbglevels.h:71
const char * MessageID
Definition: message_types.h:15