MySQL 8.4.2
Source Code Documentation
log_client.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef LOG_CLIENT_H_
25#define LOG_CLIENT_H_
26
27#include <stdio.h>
28
29#include <sstream>
30
31namespace auth_ldap_sasl_client {
32
33/**
34 LDAP plugin log levels type
35*/
42};
43
44/**
45 Log writer class.
46*/
48 public:
49 /**
50 Constructor.
51 */
53 /**
54 Destructor.
55 */
57 /**
58 Writes the data to the log.
59
60 @param data [in] the data
61 */
62 void write(const std::string &data);
63};
64
65/**
66 Class representing logger for LDAP plugins. Singleton.
67*/
69 /** type of message to be logged */
70 using Message = std::initializer_list<const char *>;
71
72 public:
73 /**
74 Creates the logger object.
75
76 @param log_level [in] log level
77 */
79 /**
80 Destroys the logger object.
81 */
82 static void destroy_logger();
83 /**
84 Log a debug message.
85
86 @param msg [in] the message
87 */
88 static void log_dbg_msg(Message msg);
89 /**
90 Log an info message.
91
92 @param msg [in] the message
93 */
94 static void log_info_msg(Message msg);
95 /**
96 Log a warning message.
97
98 @param msg [in] the message
99 */
100 static void log_warning_msg(Message msg);
101 /**
102 Log an error message.
103
104 @param msg [in] the message
105 */
106 static void log_error_msg(Message msg);
107
108 private:
109 /**
110 Private constructor to assure singleton pattern.
111
112 @param level [in] log level
113 */
115 /**
116 Destructor.
117 */
118 ~Ldap_logger();
119
120 /** Log writer */
122 /** Log level */
124 /** Pointer to the only log object */
126
127 /**
128 Compose the log message and write it.
129
130 @tparam level log level
131 @tparam prefix log level name
132
133 @param msg [in] message to be logged
134 */
135 template <ldap_log_level level, const char *prefix>
136 void log(Message msg) {
137 std::stringstream log_stream;
138 if (level > m_log_level || !m_log_writer) return;
139 log_stream << prefix << " : ";
140 for (auto &msg_element : msg) {
141 if (msg_element) log_stream << msg_element;
142 }
143 m_logger->m_log_writer->write(log_stream.str());
144 }
145};
146
147} // namespace auth_ldap_sasl_client
148/**
149 \defgroup Ldap_logger_wrappers Shortcut wrappers to the logger functions
150 @{
151*/
152#define log_dbg(...) Ldap_logger::log_dbg_msg({__VA_ARGS__})
153#define log_info(...) Ldap_logger::log_info_msg({__VA_ARGS__})
154#define log_warning(...) Ldap_logger::log_warning_msg({__VA_ARGS__})
155#define log_error(...) Ldap_logger::log_error_msg({__VA_ARGS__})
156/**@}*/
157
158#endif
Log writer class.
Definition: log_client.h:47
void write(const std::string &data)
Writes the data to the log.
Definition: log_client.cc:79
Class representing logger for LDAP plugins.
Definition: log_client.h:68
static void log_dbg_msg(Message msg)
Log a debug message.
Definition: log_client.cc:60
static void log_error_msg(Message msg)
Log an error message.
Definition: log_client.cc:74
void log(Message msg)
Compose the log message and write it.
Definition: log_client.h:136
static void log_info_msg(Message msg)
Log an info message.
Definition: log_client.cc:64
static void create_logger(ldap_log_level log_level=LDAP_LOG_LEVEL_NONE)
Creates the logger object.
Definition: log_client.cc:34
~Ldap_logger()
Destructor.
Definition: log_client.cc:49
ldap_log_level m_log_level
Log level.
Definition: log_client.h:123
static void destroy_logger()
Destroys the logger object.
Definition: log_client.cc:37
std::initializer_list< const char * > Message
type of message to be logged
Definition: log_client.h:70
static Ldap_logger * m_logger
Pointer to the only log object.
Definition: log_client.h:125
Ldap_logger(ldap_log_level level)
Private constructor to assure singleton pattern.
Definition: log_client.cc:44
Ldap_log_writer_error * m_log_writer
Log writer.
Definition: log_client.h:121
static void log_warning_msg(Message msg)
Log a warning message.
Definition: log_client.cc:69
Definition: auth_ldap_kerberos.cc:30
ldap_log_level
LDAP plugin log levels type.
Definition: log_client.h:36
@ LDAP_LOG_LEVEL_NONE
Definition: log_client.h:37
@ LDAP_LOG_LEVEL_ERROR_WARNING
Definition: log_client.h:39
@ LDAP_LOG_LEVEL_ALL
Definition: log_client.h:41
@ LDAP_LOG_LEVEL_ERROR
Definition: log_client.h:38
@ LDAP_LOG_LEVEL_ERROR_WARNING_INFO
Definition: log_client.h:40
static loglevel log_level(const Sql_condition *condition)
Definition: histogram.cc:1643