MySQL 26.10.0
Source Code Documentation
mrs_component_log.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, 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 MRS_COMPONENT_LOG_H
27#define MRS_COMPONENT_LOG_H
28
30
31namespace mrs_component {
32
33/**
34 Emits MRS messages through the MySQL Server logging services.
35*/
36class Log {
37 public:
38 void log_message(enum_log_type log_type, long long level, long long code,
39 const char *msg, ...) const
40 MY_ATTRIBUTE((format(printf, 5, 0)));
41
42 void log_message_va(enum_log_type log_type, long long level, long long code,
43 const char *msg, va_list args) const
44 MY_ATTRIBUTE((format(printf, 5, 0))) {
45 LogEvent()
46 .prio(level)
47 .errcode(code)
49 .source_line(__LINE__)
51 .function(__FUNCTION__)
54 .messagev(msg, args);
55 }
56
57 Log() = default;
58 ~Log() = default;
59 Log(const Log &) = delete;
60 Log &operator=(const Log &) = delete;
61 Log(Log &&) = delete;
62 Log &operator=(Log &&) = delete;
63};
64
65} // namespace mrs_component
66
67// Logging helper macros
68#define MRS_LOG_SYSTEM(msg, ...) \
69 do { \
70 mrs_component().log().log_message(LOG_TYPE_ERROR, SYSTEM_LEVEL, \
71 ER_MRS_COMPONENT_MSG, "%s: " msg, \
72 mrs_component().name(), ##__VA_ARGS__); \
73 } while (0)
74
75#define MRS_LOG_INFO(msg, ...) \
76 do { \
77 mrs_component().log().log_message(LOG_TYPE_ERROR, INFORMATION_LEVEL, \
78 ER_MRS_COMPONENT_INFO, "%s: " msg, \
79 mrs_component().name(), ##__VA_ARGS__); \
80 } while (0)
81
82#define MRS_LOG_WARNING(msg, ...) \
83 do { \
84 mrs_component().log().log_message(LOG_TYPE_ERROR, WARNING_LEVEL, \
85 ER_MRS_COMPONENT_WARNING, "%s: " msg, \
86 mrs_component().name(), ##__VA_ARGS__); \
87 } while (0)
88
89#define MRS_LOG_ERROR(msg, ...) \
90 do { \
91 mrs_component().log().log_message(LOG_TYPE_ERROR, ERROR_LEVEL, \
92 ER_MRS_COMPONENT_ERROR, "%s: " msg, \
93 mrs_component().name(), ##__VA_ARGS__); \
94 } while (0)
95
96#ifdef COMPONENT_MRS_LOG_DEBUG
97#define MRS_LOG_DEBUG(msg, ...) \
98 do { \
99 mrs_component().log().log_message(LOG_TYPE_ERROR, INFORMATION_LEVEL, \
100 ER_MRS_COMPONENT_MSG, "%s(DEBUG): " msg, \
101 mrs_component().name(), ##__VA_ARGS__); \
102 } while (0)
103#else
104#define MRS_LOG_DEBUG(...) \
105 do { \
106 } while (0)
107#endif // COMPONENT_MRS_LOG_DEBUG
108
109#endif // MRS_COMPONENT_LOG_H
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
Emits MRS messages through the MySQL Server logging services.
Definition: mrs_component_log.h:36
Log(const Log &)=delete
Log & operator=(Log &&)=delete
Log(Log &&)=delete
void log_message(enum_log_type log_type, long long level, long long code, const char *msg,...) const
Emits information entry into the system log.
Definition: mrs_component_log.cc:37
Log & operator=(const Log &)=delete
void log_message_va(enum_log_type log_type, long long level, long long code, const char *msg, va_list args) const
Definition: mrs_component_log.h:42
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: mrs_component.cc:137