MySQL 8.4.0
Source Code Documentation
log_suppressor.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 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 METADATA_CACHE_LOG_SUPPRESSOR_INCLUDED
27#define METADATA_CACHE_LOG_SUPPRESSOR_INCLUDED
28
29#include <map>
30#include <string>
31
33
34namespace metadata_cache {
35
36// helper class - helps to log the message about the cluster or instance only
37// when the message text (condition) changes
39 public:
40 enum class MessageId {
41 /* incorrect JSON for _disconnect_existing_sessions_when_hidden from the
42 last query */
44
45 /* incorrect JSON for _hidden in the metadata from the last query */
46 kHidden,
47
48 /* instance type incompatible with the Cluster type */
50
51 /* incorrect JSON for instance_type from the last query */
53
54 /* incorrect JSON or value for read_only_targets */
56
57 /* incorrect JSON or value for unreachable_quorum_allowed_traffic */
59
60 /* deprecated version of Cluster Metadata */
62 };
63
65 static LogSuppressor instance_;
66 return instance_;
67 }
68
69 void log_message(const MessageId id, const std::string &uuid,
70 const std::string &message, bool invalid_condition,
71 mysql_harness::logging::LogLevel invalid_condition_level =
73 mysql_harness::logging::LogLevel valid_condition_level =
75 const bool log_initial_valid = false);
76
78
79 private:
80 // the key in the map is the std::pair<uuid, message_id>
81 using MessageKey = std::pair<std::string, MessageId>;
82 std::map<MessageKey, std::string> messages_;
83
84 // singleton
85 LogSuppressor() = default;
86 LogSuppressor(const LogSuppressor &) = delete;
88};
89
90} // namespace metadata_cache
91
92#endif // METADATA_CACHE_LOG_SUPPRESSOR_INCLUDED
Definition: log_suppressor.h:38
LogSuppressor & operator=(const LogSuppressor &)=delete
LogSuppressor(const LogSuppressor &)=delete
MessageId
Definition: log_suppressor.h:40
static LogSuppressor & instance()
Definition: log_suppressor.h:64
std::map< MessageKey, std::string > messages_
Definition: log_suppressor.h:82
void log_message(const MessageId id, const std::string &uuid, const std::string &message, bool invalid_condition, mysql_harness::logging::LogLevel invalid_condition_level=mysql_harness::logging::LogLevel::kWarning, mysql_harness::logging::LogLevel valid_condition_level=mysql_harness::logging::LogLevel::kWarning, const bool log_initial_valid=false)
Definition: log_suppressor.cc:35
std::pair< std::string, MessageId > MessageKey
Definition: log_suppressor.h:81
Logging interface for using and extending the logging subsystem.
Definition: metadata_cache.h:53
LogLevel
Log level values.
Definition: logging.h:96