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