MySQL 26.10.0
Source Code Documentation
health_monitor_log.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2026, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#pragma once
25
26#include <string>
27
28#include "component_log.h"
29#include "health_monitor.h"
30#include "mysqld_error.h"
31
32namespace hm {
33
34class Log {
35 public:
36 void log_message(enum_log_type log_type, long long level, long long code,
37 const char *msg, ...) MY_ATTRIBUTE((format(printf, 5, 0)));
38
39 // cppcheck-suppress functionStatic
40 void log_message_va(enum_log_type log_type, long long level, long long code,
41 const char *msg, va_list args)
42 MY_ATTRIBUTE((format(printf, 5, 0))) {
43 LogEvent()
44 .prio(level)
45 .errcode(code)
47 .source_line(__LINE__)
49 .function(__FUNCTION__)
52 .messagev(msg, args);
53 }
54
55 template <typename... Args>
56 // cppcheck-suppress functionStatic
57 void log_message_lu(long long level, long long code, Args... args) {
58 LogEvent()
59 .prio(level)
60 .errcode(code)
62 .source_line(__LINE__)
64 .function(__FUNCTION__)
66 .lookup(code, args...);
67 }
68
69 Log();
70 ~Log() = default;
71 Log(const Log &) = delete;
72 Log &operator=(const Log &) = delete;
73 Log(Log &&) = delete;
74 Log &operator=(Log &&) = delete;
75};
76
77// Logging helper macros
78#define log_diag(msg, ...) \
79 ::hm::Health_Monitor::log()->log_message(LOG_TYPE_DIAG, INFORMATION_LEVEL, \
80 ER_DIAG_LOG_STRING, msg, \
81 ##__VA_ARGS__)
82
83#define log_info(msg, ...) \
84 ::hm::Health_Monitor::log()->log_message(LOG_TYPE_ERROR, INFORMATION_LEVEL, \
85 ER_HEALTH_INFO, msg, ##__VA_ARGS__)
86
87#define log_warning(msg, ...) \
88 ::hm::Health_Monitor::log()->log_message( \
89 LOG_TYPE_ERROR, WARNING_LEVEL, ER_HEALTH_WARNING, msg, ##__VA_ARGS__)
90
91#define log_error(msg, ...) \
92 ::hm::Health_Monitor::log()->log_message( \
93 LOG_TYPE_ERROR, ERROR_LEVEL, ER_HEALTH_ERROR, msg, ##__VA_ARGS__)
94
95#define log_warn_usage(msgno, ...) \
96 ::hm::Health_Monitor::log()->log_message_lu(WARNING_LEVEL, msgno, \
97 ##__VA_ARGS__)
98
99// Logging helper functions
100std::string bool_to_string(bool value, std::string &if_true,
101 std::string &if_false);
102const std::string eq{"="};
103std::string on_off(bool value);
104std::string true_false(bool value);
105
106} // namespace hm
Modular logger: fluid API.
Definition: log_builtins.h:924
LogEvent & prio(longlong val)
Set error message priority.
Definition: log_builtins.h:1316
LogEvent & subsys(const char *val)
Which subsystem in the source was the problem detected in? ("Repl"/"InnoDB"/"Server")
Definition: log_builtins.h:1191
LogEvent & errcode(longlong val)
Append a numeric error code.
Definition: log_builtins.h:1093
LogEvent & source_file(const char *val)
Which source file was the problem detected in?
Definition: log_builtins.h:1154
LogEvent & type(enum_log_type val)
Set log type.
Definition: log_builtins.h:1081
LogEvent & component(const char *val)
Which component in the source was the problem detected in? This should be the same string that is giv...
Definition: log_builtins.h:1206
LogEvent & function(const char *val)
Which function in the source was the problem detected in?
Definition: log_builtins.h:1178
LogEvent & source_line(longlong val)
Which line in the source file was the problem detected on?
Definition: log_builtins.h:1166
LogEvent & messagev(const char *fmt, va_list ap)
Fill in a format string by substituting the % with the given arguments, then add the result as the ev...
Definition: log_builtins.h:1376
LogEvent & lookup(longlong errcode,...)
Find an error message by its MySQL error code.
Definition: log_builtins.h:1451
Definition: health_monitor_log.h:34
Log(const Log &)=delete
Log(Log &&)=delete
void log_message(enum_log_type log_type, long long level, long long code, const char *msg,...)
Emits information entry into the system log.
Definition: health_monitor_log.cc:46
Log & operator=(Log &&)=delete
~Log()=default
void log_message_va(enum_log_type log_type, long long level, long long code, const char *msg, va_list args)
Definition: health_monitor_log.h:40
void log_message_lu(long long level, long long code, Args... args)
Definition: health_monitor_log.h:57
Log & operator=(const Log &)=delete
Log()
Initialize the globals for the MySQL logging component.
Definition: health_monitor_log.cc:34
enum_log_type
log_type – which log to send data to check vs enum_log_table_type and LOG_FILE/LOG_TABLE/LOG_NONE
Definition: log_shared.h:66
#define LOG_COMPONENT_TAG
Definition: log_sink_test.cc:25
#define LOG_SUBSYSTEM_TAG
Definition: log_sink_test.cc:27
static int log_type
Definition: mi_log.cc:47
#define MY_BASENAME
Definition: my_basename.h:40
std::string format(const routing_guidelines::Session_info &session_info, bool extended_session_info)
Definition: dest_metadata_cache.cc:170
Definition: component_command.h:29
std::string true_false(bool value)
Definition: health_monitor_log.cc:66
std::string bool_to_string(bool value, const std::string &if_true, const std::string &if_false)
Boolean to string helper functions.
Definition: health_monitor_log.cc:61
std::string on_off(bool value)
Definition: health_monitor_log.cc:65
const std::string eq
Definition: health_monitor_log.h:102
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83