MySQL 8.0.32
Source Code Documentation
logger.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2017, 2022, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
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 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
25#ifndef MYSQL_HARNESS_LOGGER_LOGGER_INCLUDED
26#define MYSQL_HARNESS_LOGGER_LOGGER_INCLUDED
27
28#include "harness_export.h"
30
31#include <set>
32#include <string>
33
34namespace mysql_harness {
35
36namespace logging {
37
38class Registry;
39
40/**
41 * Logger class.
42 *
43 * The logger class handles the logging for one or more logging
44 * handlers. Each logger class instance keeps state for logging for one
45 * module or subsystem. You can add handlers to a logger which will
46 * then be used for all logging to that subsystem.
47 */
48class HARNESS_EXPORT Logger {
49 public:
50 explicit Logger(Registry &registry, LogLevel level = kDefaultLogLevel);
51
52 // such null object is useless, however we need the ability to create an
53 // object and populate it later inside of guarded scope (e.g: std::lock_guard)
54 Logger() : level_(LogLevel::kNotSet) {}
55
56 void attach_handler(std::string name);
57 void detach_handler(std::string name, bool handler_must_exist = true);
58 void handle(const Record &record);
59
60 /**
61 * check if the log-level will be handled.
62 *
63 * log-messages may be filtered on global and on handler level.
64 *
65 * in case it is not handled, there is no need call the prepare data for
66 * the log-function.
67 *
68 * @returns if log-level will be handled or not
69 * @retval true log-level (quite likely) will be handled
70 * @retval false log-level will be ignored
71 */
72 bool is_handled(LogLevel level) const;
73 const std::set<std::string> &get_handler_names() const { return handlers_; }
74
75 void set_level(LogLevel level) { level_ = level; }
76 LogLevel get_level() const { return level_; }
78 precision_ = precision;
79 }
80 LogTimestampPrecision get_timestamp_precision() const { return precision_; }
81
82 private:
85 std::set<std::string> handlers_;
86 const Registry *registry_; // owner backreference (we don't own Registry,
87 // Registry owns us)
88};
89
90} // namespace logging
91
92} // namespace mysql_harness
93
94#endif /* MYSQL_HARNESS_LOGGER_LOGGER_INCLUDED */
Logger class.
Definition: logger.h:48
const Registry * registry_
Definition: logger.h:86
std::set< std::string > handlers_
Definition: logger.h:85
LogLevel get_level() const
Definition: logger.h:76
LogLevel level_
Definition: logger.h:83
void set_level(LogLevel level)
Definition: logger.h:75
const std::set< std::string > & get_handler_names() const
Definition: logger.h:73
Logger()
Definition: logger.h:54
LogTimestampPrecision precision_
Definition: logger.h:84
LogTimestampPrecision get_timestamp_precision() const
Definition: logger.h:80
void set_timestamp_precision(LogTimestampPrecision precision)
Definition: logger.h:77
Definition: registry.h:46
Logging interface for using and extending the logging subsystem.
const LogLevel kDefaultLogLevel
Default log level used by the router.
Definition: logging.h:145
LogLevel
Log level values.
Definition: logging.h:95
LogTimestampPrecision
Log timestamp precision values.
Definition: logging.h:160
Definition: common.h:41
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service.
Definition: services.cc:64
case opt name
Definition: sslopt-case.h:32
Log record containing information collected by the logging system.
Definition: logging.h:182
Definition: mi_test3.cc:54