Kea 2.7.5
db_log.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2024 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
12#include <database/db_log.h>
14
15using namespace isc::log;
16
17namespace isc {
18namespace db {
19
22
43
45
47
49
50std::mutex db_logger_mutex;
51
52const MessageID&
54 try {
55 return (map_.at(id));
56 } catch (const std::out_of_range&) {
57 isc_throw(isc::Unexpected, "can't map message: " << id);
58 }
59}
60
62 if (db_logger_stack.empty()) {
63 isc_throw(isc::Unexpected, "database logger stack is empty");
64 }
65}
66
67template <>
69DB_LOG<fatal>::formatter(DbMessageID const message_id,
70 int const /* debug_level = 0 */) {
71 return isc::db::db_logger_stack.back().logger_.fatal(
72 isc::db::db_logger_stack.back().translateMessage(message_id));
73}
74
75template <>
77DB_LOG<error>::formatter(DbMessageID const message_id,
78 int const /* debug_level = 0 */) {
79 return isc::db::db_logger_stack.back().logger_.error(
80 isc::db::db_logger_stack.back().translateMessage(message_id));
81}
82
83template <>
85DB_LOG<warn>::formatter(DbMessageID const message_id,
86 int const /* debug_level = 0 */) {
87 return isc::db::db_logger_stack.back().logger_.warn(
88 isc::db::db_logger_stack.back().translateMessage(message_id));
89}
90
91template <>
93DB_LOG<info>::formatter(DbMessageID const message_id,
94 int const /* debug_level = 0 */) {
95 return isc::db::db_logger_stack.back().logger_.info(
96 isc::db::db_logger_stack.back().translateMessage(message_id));
97}
98
99template <>
101DB_LOG<debug>::formatter(DbMessageID const message_id,
102 int const debug_level /* = 0 */) {
103 return isc::db::db_logger_stack.back().logger_.debug(
104 debug_level,
105 isc::db::db_logger_stack.back().translateMessage(message_id));
106}
107
108template <>
109bool
110DB_LOG<fatal>::isEnabled(int const /* debug_level = 0 */) const {
111 return db_logger_stack.back().logger_.isFatalEnabled();
112}
113
114template <>
115bool
116DB_LOG<error>::isEnabled(int const /* debug_level = 0 */) const {
117 return db_logger_stack.back().logger_.isErrorEnabled();
118}
119
120template <>
121bool
122DB_LOG<warn>::isEnabled(int const /* debug_level = 0 */) const {
123 return db_logger_stack.back().logger_.isWarnEnabled();
124}
125
126template <>
127bool
128DB_LOG<info>::isEnabled(int const /* debug_level = 0 */) const {
129 return db_logger_stack.back().logger_.isInfoEnabled();
130}
131
132template <>
133bool
134DB_LOG<debug>::isEnabled(int const debug_level /* = 0 */) const {
135 return db_logger_stack.back().logger_.isDebugEnabled(debug_level);
136}
137
138} // namespace db
139} // namespace isc
A generic exception that is thrown when an unexpected error condition occurs.
const MessageMap & map_
The translation map.
Definition db_log.h:98
const isc::log::MessageID & translateMessage(const DbMessageID &id) const
Translate message.
Definition db_log.cc:53
std::map< DbMessageID, isc::log::MessageID > MessageMap
Translation map type.
Definition db_log.h:77
The log message formatter.
Logger Class.
Definition log/logger.h:142
We want to reuse the database backend connection and exchange code for other uses,...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
const int DB_DBG_TRACE_DETAIL
Database logging levels.
Definition db_log.cc:21
const isc::log::MessageID DATABASE_PGSQL_FATAL_ERROR
Definition db_messages.h:20
isc::log::Logger database_logger("database")
Common database library logger.
Definition db_log.h:46
const isc::log::MessageID DATABASE_MYSQL_COMMIT
Definition db_messages.h:12
std::list< DbLogger > DbLoggerStack
Database logger stack.
Definition db_log.h:102
const isc::log::MessageID DATABASE_MYSQL_INITIALIZE_SCHEMA
Definition db_messages.h:14
const isc::log::MessageID DATABASE_PGSQL_INITIALIZE_SCHEMA
Definition db_messages.h:21
DbMessageID
Database messages.
Definition db_log.h:51
@ DB_INVALID_ACCESS
Definition db_log.h:52
@ MYSQL_START_TRANSACTION
Definition db_log.h:66
@ PGSQL_ROLLBACK_SAVEPOINT
Definition db_log.h:61
@ PGSQL_CREATE_SAVEPOINT
Definition db_log.h:60
@ PGSQL_ROLLBACK
Definition db_log.h:59
@ MYSQL_INITIALIZE_SCHEMA
Definition db_log.h:64
@ PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED
Definition db_log.h:62
@ PGSQL_COMMIT
Definition db_log.h:58
@ PGSQL_START_TRANSACTION
Definition db_log.h:57
@ PGSQL_FATAL_ERROR
Definition db_log.h:56
@ MYSQL_ROLLBACK
Definition db_log.h:68
@ PGSQL_INITIALIZE_SCHEMA
Definition db_log.h:54
@ PGSQL_DEALLOC_ERROR
Definition db_log.h:55
@ MYSQL_FATAL_ERROR
Definition db_log.h:65
@ MYSQL_COMMIT
Definition db_log.h:67
const isc::log::MessageID DATABASE_PGSQL_COMMIT
Definition db_messages.h:17
DbLoggerStack db_logger_stack
Global database logger stack (initialized to database logger)
Definition db_log.cc:48
const isc::log::MessageID DATABASE_PGSQL_CREATE_SAVEPOINT
Definition db_messages.h:18
const isc::log::MessageID DATABASE_INVALID_ACCESS
Definition db_messages.h:11
const isc::log::MessageID DATABASE_PGSQL_ROLLBACK_SAVEPOINT
Definition db_messages.h:23
const isc::log::MessageID DATABASE_MYSQL_ROLLBACK
Definition db_messages.h:15
std::mutex db_logger_mutex
Global mutex to protect logger stack.
Definition db_log.cc:50
void checkDbLoggerStack()
Check database logger stack.
Definition db_log.cc:61
const isc::log::MessageID DATABASE_PGSQL_DEALLOC_ERROR
Definition db_messages.h:19
const DbLogger::MessageMap db_message_map
Map of translated messages.
Definition db_log.cc:24
DbLogger db_logger_translator(database_logger, db_message_map)
Database logger translator.
Definition db_log.h:212
const isc::log::MessageID DATABASE_PGSQL_START_TRANSACTION
Definition db_messages.h:24
const isc::log::MessageID DATABASE_PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED
Definition db_messages.h:25
const isc::log::MessageID DATABASE_PGSQL_ROLLBACK
Definition db_messages.h:22
const isc::log::MessageID DATABASE_MYSQL_FATAL_ERROR
Definition db_messages.h:13
const isc::log::MessageID DATABASE_MYSQL_START_TRANSACTION
Definition db_messages.h:16
const char * MessageID
const int DBGLVL_TRACE_DETAIL
Trace detailed operations.
Defines the logger used by the top-level component of kea-lfc.