MySQL  8.0.20
Source Code Documentation
log_client.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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_H_
24 #define LOG_H_
25 
26 #include <stdio.h>
27 #include <iostream>
28 #include <sstream>
29 
30 struct ldap_log_type {
31  typedef enum {
36  } ldap_type;
37 };
38 
45 };
46 
48  public:
51  void write(std::string data);
52 };
53 
54 class Ldap_logger {
55  public:
56  Ldap_logger();
57  ~Ldap_logger();
58  template <ldap_log_type::ldap_type type>
59  void log(std::string msg);
60  void set_log_level(ldap_log_level level);
61 
62  private:
65 };
66 
67 template <ldap_log_type::ldap_type type>
68 void Ldap_logger::log(std::string msg) {
69  std::stringstream log_stream;
70  switch (type) {
72  if (LDAP_LOG_LEVEL_ALL > m_log_level) {
73  return;
74  }
75  log_stream << "[DBG] ";
76  break;
78  if (LDAP_LOG_LEVEL_ERROR_WARNING_INFO > m_log_level) {
79  return;
80  }
81  log_stream << "[Note] ";
82  break;
84  if (LDAP_LOG_LEVEL_ERROR_WARNING > m_log_level) {
85  return;
86  }
87  log_stream << "[Warning] ";
88  break;
90  if (LDAP_LOG_LEVEL_NONE >= m_log_level) {
91  return;
92  }
93  log_stream << "[Error] ";
94  break;
95  };
96 
97  /** We can write debug messages also in error log file if logging level is set
98  to debug. For MySQL client this will come from environment variable */
99  if (m_log_writer) {
100  log_stream << ": " << msg;
101  m_log_writer->write(log_stream.str());
102  }
103 }
104 
106 
107 #define log_dbg g_logger_client->log<ldap_log_type::LDAP_LOG_DBG>
108 #define log_info g_logger_client->log<ldap_log_type::LDAP_LOG_INFO>
109 #define log_warning g_logger->log<ldap_log_type::LDAP_LOG_WARNING>
110 #define log_error g_logger_client->log<ldap_log_type::LDAP_LOG_ERROR>
111 
112 #endif
Definition: log_client.h:54
void log(std::string msg)
Definition: log_client.h:68
Definition: log_client.h:35
Definition: log_client.h:42
Definition: log_client.h:41
Definition: log_client.h:40
Definition: log_client.h:34
void write(W *w, const T &t, const char *key, size_t key_sz)
Definition: sdi_impl.h:333
ldap_log_level
Definition: log_client.h:39
Definition: log_client.h:47
static void set_log_level(EXTENSION_LOG_LEVEL severity)
Definition: memcached.c:6822
ldap_type
Definition: log_client.h:31
Definition: log_client.h:33
Definition: log_client.h:30
Ldap_logger * g_logger_client
Definition: auth_ldap_kerberos.cc:33
ldap_log_level m_log_level
Definition: log_client.h:64
Definition: log_client.h:43
char msg[1024]
Definition: test_sql_9_sessions.cc:281
Definition: log_client.h:44
Ldap_log_writer_error * m_log_writer
Definition: log_client.h:63
Definition: log_client.h:32