MySQL  8.0.19
Source Code Documentation
logger.h
Go to the documentation of this file.
1 #ifndef LOGGER_UTIL_INCLUDED
2 #define LOGGER_UTIL_INCLUDED
3 /*
4  Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License, version 2.0,
8  as published by the Free Software Foundation.
9 
10  This program is also distributed with certain software (including
11  but not limited to OpenSSL) that is licensed under separate terms,
12  as designated in a particular file or component or in included license
13  documentation. The authors of MySQL hereby grant you an additional
14  permission to link the program and your derivative works with the
15  separately licensed software that they have included with MySQL.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License, version 2.0, for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26 
27 #include <stddef.h>
28 #include <ostream>
29 #include <sstream>
30 #include <string>
31 
32 struct Datetime {};
33 
34 std::ostream &operator<<(std::ostream &os, const Datetime &dt);
35 
36 class Gen_spaces {
37  public:
38  Gen_spaces(int s) { m_spaces.assign(s, ' '); }
39  std::ostream &operator<<(std::ostream &os) { return os; }
40  friend std::ostream &operator<<(std::ostream &os, const Gen_spaces &gen);
41 
42  private:
43  std::string m_spaces;
44 };
45 
46 std::ostream &operator<<(std::ostream &os, const Gen_spaces &gen);
47 
48 class Log : public std::ostream {
49  public:
50  Log(std::ostream &str, std::string logclass)
51  : std::ostream(NULL), m_buffer(str, logclass) {
52  this->init(&m_buffer);
53  }
54  void enabled(bool s) { m_buffer.enabled(s); }
55 
56  private:
57  class Log_buff : public std::stringbuf {
58  public:
59  Log_buff(std::ostream &str, std::string &logc)
60  : m_os(str), m_logc(logc), m_enabled(true) {}
61  void set_log_class(std::string &s) { m_logc = s; }
62  void enabled(bool s) { m_enabled = s; }
63  virtual int sync();
64 
65  private:
66  std::ostream &m_os;
67  std::string m_logc;
68  bool m_enabled;
69  };
70 
72 };
73 
74 #endif /* LOGGER_UTIL_INCLUDED */
Log::Log_buff
Definition: logger.h:57
Log::Log_buff::Log_buff
Log_buff(std::ostream &str, std::string &logc)
Definition: logger.h:59
NULL
#define NULL
Definition: types.h:55
Log::m_buffer
Log_buff m_buffer
Definition: logger.h:71
Log::Log
Log(std::ostream &str, std::string logclass)
Definition: logger.h:50
Gen_spaces::m_spaces
std::string m_spaces
Definition: logger.h:43
Gen_spaces::operator<<
std::ostream & operator<<(std::ostream &os)
Definition: logger.h:39
Log::enabled
void enabled(bool s)
Definition: logger.h:54
true
#define true
Definition: config_static.h:44
Log::Log_buff::sync
virtual int sync()
Definition: logger.cc:49
Log::Log_buff::m_enabled
bool m_enabled
Definition: logger.h:68
Log
Definition: logger.h:48
Datetime
Definition: logger.h:32
Log::Log_buff::m_os
std::ostream & m_os
Definition: logger.h:66
Gen_spaces::Gen_spaces
Gen_spaces(int s)
Definition: logger.h:38
Log::Log_buff::set_log_class
void set_log_class(std::string &s)
Definition: logger.h:61
operator<<
std::ostream & operator<<(std::ostream &os, const Datetime &dt)
Definition: logger.cc:33
std
Definition: varlen_sort.h:182
Log::Log_buff::m_logc
std::string m_logc
Definition: logger.h:67
Gen_spaces
Definition: logger.h:36
init
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:574
stringbuf
static char * stringbuf
Definition: lexyy.cc:926
Log::Log_buff::enabled
void enabled(bool s)
Definition: logger.h:62