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