MySQL 8.0.40
Source Code Documentation
logger.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2017, 2024, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_HARNESS_LOGGER_LOGGER_INCLUDED
27#define MYSQL_HARNESS_LOGGER_LOGGER_INCLUDED
28
29#include "harness_export.h"
31
32#include <set>
33#include <string>
34
35namespace mysql_harness {
36
37namespace logging {
38
39class Registry;
40
41/**
42 * Logger class.
43 *
44 * The logger class handles the logging for one or more logging
45 * handlers. Each logger class instance keeps state for logging for one
46 * module or subsystem. You can add handlers to a logger which will
47 * then be used for all logging to that subsystem.
48 */
49class HARNESS_EXPORT Logger {
50 public:
51 explicit Logger(Registry &registry, LogLevel level = kDefaultLogLevel);
52
53 // such null object is useless, however we need the ability to create an
54 // object and populate it later inside of guarded scope (e.g: std::lock_guard)
55 Logger() : level_(LogLevel::kNotSet) {}
56
57 void attach_handler(std::string name);
58 void detach_handler(std::string name, bool handler_must_exist = true);
59 void handle(const Record &record);
60
61 /**
62 * check if the log-level will be handled.
63 *
64 * log-messages may be filtered on global and on handler level.
65 *
66 * in case it is not handled, there is no need call the prepare data for
67 * the log-function.
68 *
69 * @returns if log-level will be handled or not
70 * @retval true log-level (quite likely) will be handled
71 * @retval false log-level will be ignored
72 */
73 bool is_handled(LogLevel level) const;
74 const std::set<std::string> &get_handler_names() const { return handlers_; }
75
76 void set_level(LogLevel level) { level_ = level; }
77 LogLevel get_level() const { return level_; }
79 precision_ = precision;
80 }
81 LogTimestampPrecision get_timestamp_precision() const { return precision_; }
82
83 private:
86 std::set<std::string> handlers_;
87 const Registry *registry_; // owner backreference (we don't own Registry,
88 // Registry owns us)
89};
90
91} // namespace logging
92
93} // namespace mysql_harness
94
95#endif /* MYSQL_HARNESS_LOGGER_LOGGER_INCLUDED */
Logger class.
Definition: logger.h:49
const Registry * registry_
Definition: logger.h:87
std::set< std::string > handlers_
Definition: logger.h:86
LogLevel get_level() const
Definition: logger.h:77
LogLevel level_
Definition: logger.h:84
void set_level(LogLevel level)
Definition: logger.h:76
const std::set< std::string > & get_handler_names() const
Definition: logger.h:74
Logger()
Definition: logger.h:55
LogTimestampPrecision precision_
Definition: logger.h:85
LogTimestampPrecision get_timestamp_precision() const
Definition: logger.h:81
void set_timestamp_precision(LogTimestampPrecision precision)
Definition: logger.h:78
Definition: registry.h:47
Logging interface for using and extending the logging subsystem.
static int record
Definition: mysqltest.cc:188
const LogLevel kDefaultLogLevel
Default log level used by the router.
Definition: logging.h:146
LogLevel
Log level values.
Definition: logging.h:96
LogTimestampPrecision
Log timestamp precision values.
Definition: logging.h:161
Definition: common.h:42
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:33
Log record containing information collected by the logging system.
Definition: logging.h:183