MySQL 9.7.0
Source Code Documentation
tm_log.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 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, version 2.0, 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 TELEMETRY_LOG_H_INCLUDED
27#define TELEMETRY_LOG_H_INCLUDED
28
30#include <mysqld_error.h>
31
32namespace telemetry {
33
34extern const char *component_name;
35
36class Log {
37 public:
38 static void init(SERVICE_TYPE(log_builtins) * log_bi_srv,
39 SERVICE_TYPE(log_builtins_string) * log_bs_srv);
40
41 static void log_message(const char *src_file, int src_line, long long level,
42 long long code, const char *msg, ...)
43 MY_ATTRIBUTE((format(printf, 5, 0)));
44
45 static void log_message_va(const char *src_file, int src_line,
46 long long level, long long code, const char *msg,
47 va_list args)
48 MY_ATTRIBUTE((format(printf, 5, 0))) {
49 LogEvent()
51 .prio(level)
52 .errcode(code)
54 .source_line(src_line)
55 .source_file(src_file)
56 .function(__FUNCTION__)
58 .messagev(msg, args);
59 }
60
61 template <typename... Args>
62 static void log_message_lu(const char *src_file, int src_line,
63 long long level, long long code, Args... args) {
64 LogEvent()
66 .prio(level)
67 .errcode(code)
69 .source_line(src_line)
70 .source_file(src_file)
71 .function(__FUNCTION__)
73 .lookup(code, args...);
74 }
75};
76
77} // namespace telemetry
78
79#define log_info(msg, ...) \
80 Log::log_message(__FILE__, __LINE__, INFORMATION_LEVEL, ER_TELEMETRY_INFO, \
81 msg, ##__VA_ARGS__)
82
83#define log_warning(msg, ...) \
84 Log::log_message(__FILE__, __LINE__, WARNING_LEVEL, ER_TELEMETRY_WARNING, \
85 msg, ##__VA_ARGS__)
86
87#define log_error(msg, ...) \
88 Log::log_message(__FILE__, __LINE__, ERROR_LEVEL, ER_TELEMETRY_ERROR, msg, \
89 ##__VA_ARGS__)
90
91#define log_warn_usage(msgno, ...) \
92 Log::log_message_lu(__FILE__, __LINE__, WARNING_LEVEL, msgno, ##__VA_ARGS__)
93
94#endif /* TELEMETRY_LOG_H_INCLUDED */
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 & 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
LogEvent & no_telemetry()
Mark log line to skip being additionally emitted as a telemetry log record.
Definition: log_builtins.h:1563
Definition: tm_log.h:36
static void log_message(const char *src_file, int src_line, long long level, long long code, const char *msg,...)
Definition: tm_log.cc:43
static void log_message_lu(const char *src_file, int src_line, long long level, long long code, Args... args)
Definition: tm_log.h:62
static void log_message_va(const char *src_file, int src_line, long long level, long long code, const char *msg, va_list args)
Definition: tm_log.h:45
static void init(const mysql_service_log_builtins_t *log_bi_srv, const mysql_service_log_builtins_string_t *log_bs_srv)
Definition: tm_log.cc:37
#define LOG_COMPONENT_TAG
Definition: log_sink_test.cc:25
#define LOG_SUBSYSTEM_TAG
Definition: log_sink_test.cc:27
std::string format(const routing_guidelines::Session_info &session_info, bool extended_session_info)
Definition: dest_metadata_cache.cc:170
Definition: option_usage.cc:40
const char * component_name
Definition: tm_component.cc:97
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76