MySQL 8.0.29
Source Code Documentation
log_shared.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef LOG_SHARED_H
24#define LOG_SHARED_H
25
27
28#include "my_basename.h"
29#include "my_inttypes.h"
30#include "my_loglevel.h"
31
32/** fallback: includer may not have set this to something sensible. */
33#ifndef LOG_SUBSYSTEM_TAG
34#define LOG_SUBSYSTEM_TAG NULL
35#endif
36
37/**
38 The logging sub-system internally uses the log_line structure to pass
39 data around. This header primarily the specifics and symbols of that
40 structure.
41
42 Within the server, those interfaces may be used, but it is usually
43 preferable to use the fluent C++ convenience class LogErr() instead
44 where possible (and the variadic convenience function log_message()
45 where it is not). (see sql/log.h).
46
47 Finally, this header defines log types (error log etc.) as well
48 as log item types (timestamp, message, ...) used by the logging
49 components; these are shared between the variadic convenience
50 functions (log_message() etc.) as well as the lower level services
51 using the log_line structure.
52*/
53
54/*
55 By historical convention in the lex context,
56 CSTRING means "constant lex string (char * + size_t)",
57 not "C-style string" (char *, \0 terminated)!
58*/
60
61/**
62 log_type -- which log to send data to
63 check vs enum_log_table_type and LOG_FILE/LOG_TABLE/LOG_NONE
64*/
71 LOG_TYPE_MISC = 16
72};
73
74/**
75 item_type -- what to log
76
77
78 Used by variadic convenience interface
79 log_message(), legacy sql_print_*(), legacy my_plugin_log_message().
80 Also available via the log_builtins service as message().
81
82 (Wherever possible, use the fluent C++ wrapper LogErr() (see
83 log_builtins.h) instead, though.)
84
85 LOG_ITEM_GEN_CSTRING lets the caller submit a \0 terminated,
86 C-style string for convenience; it will be converted to
87 lex style (char *, size_t) on submission.
88
89 LOG_ITEM_END should not be used in the variadic interface
90 as submitting a log line without an actual message is discouraged.
91 Instead LOG_ITEM_LOG_MESSAGE or LOG_ITEM_LOG_LOOKUP should be used
92 as the last LOG_ITEM_* key-value pairs:
93
94 - LOG_ITEM_LOG_MESSAGE can be used to submit an ad hoc message
95 directly while debugging.
96
97 - LOG_ITEM_LOG_LOOKUP asks for the given error number to be
98 replaced by the associated error message (i.e. the error message
99 for the error number will be looked up, and the LOOKUP item will
100 be replaced by a MESSAGE one).
101
102 In variadic submission, both ad hoc and well-known error messages
103 are considered printf()-style format strings, and should be followed
104 by any arguments/variables required by that format string.
105
106 In some situations, the variadic interface will automatically
107 generate some items ("If you cannot afford a timestamp, one will
108 be provided for you."). If an item of the required type already
109 exists, the submission interface should not generate another.
110
111 Old-style plug-ins using my_plugin_log_message() will automatically
112 be tagged with a default LOG_ITEM_MSC_COMPONENT of their plug-in name.
113
114
115
116 Non-variadic interface
117
118 In non-variadic submission (i.e. all functions accepting a log_line),
119 LOG_ITEM_LOG_LOOKUP and LOG_ITEM_GEN_CSTRING are not valid item types,
120 while LOG_ITEM_LOG_MESSAGE must already be a string literal (i.e. any
121 substitutions must already have taken place).
122*/
123typedef enum enum_log_item_type {
124 LOG_ITEM_END = 0, /**< end of list, see above */
125 LOG_ITEM_LOG_TYPE = 1 << 0, /**< error log, etc. */
126 LOG_ITEM_SQL_ERRCODE = 1 << 1, /**< mysql error code (numeric) */
127 LOG_ITEM_SQL_ERRSYMBOL = 1 << 2, /**< mysql error code (symbolic) */
128 LOG_ITEM_SQL_STATE = 1 << 3, /**< SQL state */
129 LOG_ITEM_SYS_ERRNO = 1 << 4, /**< OS errno */
130 LOG_ITEM_SYS_STRERROR = 1 << 5, /**< OS strerror() */
131 LOG_ITEM_SRC_FILE = 1 << 6, /**< log called from file ... */
132 LOG_ITEM_SRC_LINE = 1 << 7, /**< log called from line ... */
133 LOG_ITEM_SRC_FUNC = 1 << 8, /**< log called from function ... */
134 LOG_ITEM_SRV_SUBSYS = 1 << 9, /**< log called from subsystem ... */
135 LOG_ITEM_SRV_COMPONENT = 1 << 10, /**< log called from component ... */
136 LOG_ITEM_MSC_USER = 1 << 11, /**< offending thread owned by ... */
137 LOG_ITEM_MSC_HOST = 1 << 12, /**< responsible user on host ... */
138 LOG_ITEM_SRV_THREAD = 1 << 13, /**< connection ID */
139 LOG_ITEM_SQL_QUERY_ID = 1 << 14, /**< query ID */
140 LOG_ITEM_SQL_TABLE_NAME = 1 << 15, /**< table name */
141 LOG_ITEM_LOG_PRIO = 1 << 16, /**< log priority (error, warn, ...) */
142 LOG_ITEM_LOG_LABEL = 1 << 17, /**< label, unless auto-derived */
143 LOG_ITEM_LOG_VERBATIM = 1 << 18, /**< the message, no % substitutions */
144 LOG_ITEM_LOG_MESSAGE = 1 << 19, /**< the message, format string */
145 LOG_ITEM_LOG_LOOKUP = 1 << 20, /**< insert message by error-code */
146 LOG_ITEM_LOG_TIMESTAMP = 1 << 21, /**< ISO8601 timestamp */
147 LOG_ITEM_LOG_TS = 1 << 22, /**< millisecs since epoch */
148 LOG_ITEM_LOG_BUFFERED = 1 << 23, /**< integer timestamp if/when buffered */
149 LOG_ITEM_LOG_SUPPRESSED = 1 << 24, /**< "and ... more" throttled */
150 LOG_ITEM_GEN_FLOAT = 1 << 25, /**< float not otherwise specified */
151 LOG_ITEM_GEN_INTEGER = 1 << 26, /**< integer not otherwise specified */
152 LOG_ITEM_GEN_LEX_STRING = 1 << 27, /**< lex string not otherwise specified */
153 LOG_ITEM_GEN_CSTRING = 1 << 28, /**< C-string not otherwise specified */
154 LOG_ITEM_GEN_BUFFER = 1 << 29, /**< optional buffer; set type on use */
155 LOG_ITEM_RET_BUFFER = 1 << 30 /**< sink's output to pfs table */
157
158/* some suggested keys for generic items */
159
160/** DIAGNOSTICS: for da->message_text() */
161#define LOG_TAG_DIAG "DIAGNOSTICS"
162
163/** AUX: supplementary data not fitting any of the wellknown keys */
164#define LOG_TAG_AUX "AUX"
165
166/* data type */
168 LOG_UNTYPED = 0, /**< undefined */
169 LOG_CSTRING = 1, /**< string (char * + \0; variadic API only) */
170 LOG_INTEGER = 2, /**< integer (long long) */
171 LOG_FLOAT = 3, /**< float (double) */
172 LOG_LEX_STRING = 4, /**< string (const char *, size_t) */
173 LOG_BUFFER = 5 /**< string (char *, size_t) */
175
176/* do we need to release any parts of the item after use? */
182
183/* union: payload */
184typedef union _log_item_data {
190
191/* item key: for now, a C-string */
192typedef const char *log_item_key;
193
194/* log item: key/value */
195typedef struct _log_item {
202
203/* service helpers */
213
214/** a bit mask of log_types. standardizing the width to 64 bit. */
216
217/** log line: a collection of log items */
218typedef struct _log_line log_line;
219
220/** log iter: an iterator over the collection of log items in a log line */
222
223/** advisory. components must not rely on others using the same value. */
224#define LOG_BUFF_MAX 8192
225
226/**
227 size of a full ISO 8601 timestamp:
228 - 19 for date/time 2022-02-22T12:34:56
229 - 7 for microsecond part .123456
230 - 6 for tzinfo tail +14:30
231 - 1 for terminator \0
232*/
233static const int iso8601_size = 33;
234
235/**
236 index of first server error message: messages with this index or
237 higher are intended for the error log; messages below this index
238 are intended for the client
239*/
240#define ER_SERVER_RANGE_START 10000
241
242#endif
static const int iso8601_size
size of a full ISO 8601 timestamp:
Definition: log_shared.h:233
enum_log_item_error
Definition: log_shared.h:204
@ LOG_ITEM_STRING_NULL
Definition: log_shared.h:210
@ LOG_ITEM_OK
Definition: log_shared.h:205
@ LOG_ITEM_KEY_NULL
Definition: log_shared.h:211
@ LOG_ITEM_KEY_MISMATCH
Definition: log_shared.h:209
@ LOG_ITEM_TYPE_NOT_FOUND
Definition: log_shared.h:206
@ LOG_ITEM_CLASS_MISMATCH
Definition: log_shared.h:208
@ LOG_ITEM_TYPE_RESERVED
Definition: log_shared.h:207
union _log_item_data log_item_data
enum enum_log_item_class log_item_class
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:65
@ LOG_TYPE_SLOW
Definition: log_shared.h:69
@ LOG_TYPE_ERROR
Definition: log_shared.h:67
@ LOG_TYPE_UNDEF
Definition: log_shared.h:66
@ LOG_TYPE_AUDIT
Definition: log_shared.h:70
@ LOG_TYPE_GENERAL
Definition: log_shared.h:68
@ LOG_TYPE_MISC
Definition: log_shared.h:71
enum_log_item_type
item_type – what to log
Definition: log_shared.h:123
@ LOG_ITEM_SRV_COMPONENT
log called from component ...
Definition: log_shared.h:135
@ LOG_ITEM_SRC_FUNC
log called from function ...
Definition: log_shared.h:133
@ LOG_ITEM_LOG_LABEL
label, unless auto-derived
Definition: log_shared.h:142
@ LOG_ITEM_LOG_TIMESTAMP
ISO8601 timestamp.
Definition: log_shared.h:146
@ LOG_ITEM_END
end of list, see above
Definition: log_shared.h:124
@ LOG_ITEM_GEN_BUFFER
optional buffer; set type on use
Definition: log_shared.h:154
@ LOG_ITEM_SQL_QUERY_ID
query ID
Definition: log_shared.h:139
@ LOG_ITEM_SQL_ERRSYMBOL
mysql error code (symbolic)
Definition: log_shared.h:127
@ LOG_ITEM_GEN_FLOAT
float not otherwise specified
Definition: log_shared.h:150
@ LOG_ITEM_LOG_TYPE
error log, etc.
Definition: log_shared.h:125
@ LOG_ITEM_SRC_FILE
log called from file ...
Definition: log_shared.h:131
@ LOG_ITEM_SQL_TABLE_NAME
table name
Definition: log_shared.h:140
@ LOG_ITEM_MSC_USER
offending thread owned by ...
Definition: log_shared.h:136
@ LOG_ITEM_LOG_MESSAGE
the message, format string
Definition: log_shared.h:144
@ LOG_ITEM_GEN_INTEGER
integer not otherwise specified
Definition: log_shared.h:151
@ LOG_ITEM_LOG_PRIO
log priority (error, warn, ...)
Definition: log_shared.h:141
@ LOG_ITEM_SRV_SUBSYS
log called from subsystem ...
Definition: log_shared.h:134
@ LOG_ITEM_LOG_TS
millisecs since epoch
Definition: log_shared.h:147
@ LOG_ITEM_SYS_ERRNO
OS errno.
Definition: log_shared.h:129
@ LOG_ITEM_RET_BUFFER
sink's output to pfs table
Definition: log_shared.h:155
@ LOG_ITEM_LOG_VERBATIM
the message, no % substitutions
Definition: log_shared.h:143
@ LOG_ITEM_LOG_SUPPRESSED
"and ... more" throttled
Definition: log_shared.h:149
@ LOG_ITEM_SQL_ERRCODE
mysql error code (numeric)
Definition: log_shared.h:126
@ LOG_ITEM_SRV_THREAD
connection ID
Definition: log_shared.h:138
@ LOG_ITEM_SRC_LINE
log called from line ...
Definition: log_shared.h:132
@ LOG_ITEM_GEN_LEX_STRING
lex string not otherwise specified
Definition: log_shared.h:152
@ LOG_ITEM_LOG_BUFFERED
integer timestamp if/when buffered
Definition: log_shared.h:148
@ LOG_ITEM_MSC_HOST
responsible user on host ...
Definition: log_shared.h:137
@ LOG_ITEM_LOG_LOOKUP
insert message by error-code
Definition: log_shared.h:145
@ LOG_ITEM_SYS_STRERROR
OS strerror()
Definition: log_shared.h:130
@ LOG_ITEM_SQL_STATE
SQL state.
Definition: log_shared.h:128
@ LOG_ITEM_GEN_CSTRING
C-string not otherwise specified.
Definition: log_shared.h:153
enum_log_item_class
Definition: log_shared.h:167
@ LOG_BUFFER
string (char *, size_t)
Definition: log_shared.h:173
@ LOG_LEX_STRING
string (const char *, size_t)
Definition: log_shared.h:172
@ LOG_UNTYPED
undefined
Definition: log_shared.h:168
@ LOG_FLOAT
float (double)
Definition: log_shared.h:171
@ LOG_CSTRING
string (char * + \0; variadic API only)
Definition: log_shared.h:169
@ LOG_INTEGER
integer (long long)
Definition: log_shared.h:170
enum enum_log_item_error log_item_error
struct _log_item log_item
enum_log_item_free
Definition: log_shared.h:177
@ LOG_ITEM_FREE_KEY
Definition: log_shared.h:179
@ LOG_ITEM_FREE_NONE
Definition: log_shared.h:178
@ LOG_ITEM_FREE_VALUE
Definition: log_shared.h:180
const char * log_item_key
Definition: log_shared.h:192
enum enum_log_item_type log_item_type
item_type – what to log
uint64 log_item_type_mask
a bit mask of log_types.
Definition: log_shared.h:215
A macro that gives FILE without the directory name (e.g.
Some integer typedefs for easier portability.
long long int longlong
Definition: my_inttypes.h:54
uint64_t uint64
Definition: my_inttypes.h:68
uint32_t uint32
Definition: my_inttypes.h:66
Definition of the global "loglevel" enumeration.
Definition: mysql_lex_string.h:39
Definition: mysql_lex_string.h:34
Iterator over the key/value pairs of a log_line.
Definition: keyring_log_builtins_definition.cc:63
Definition: log_shared.h:195
log_item_key key
Definition: log_shared.h:198
log_item_data data
Definition: log_shared.h:199
log_item_type type
Definition: log_shared.h:196
uint32 alloc
Definition: log_shared.h:200
log_item_class item_class
Definition: log_shared.h:197
log_line ("log event")
Definition: keyring_log_builtins_definition.cc:71
Definition: log_shared.h:184
MYSQL_LEX_CSTRING data_string
Definition: log_shared.h:187
double data_float
Definition: log_shared.h:186
longlong data_integer
Definition: log_shared.h:185
MYSQL_LEX_STRING data_buffer
Definition: log_shared.h:188