MySQL 9.1.0
Source Code Documentation
log_service.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/**
25 @brief
26
27 This defines the API used to call functions in logging components.
28 When implementing such a service, refer to log_service_imp.h instead!
29
30 A log service may take the shape of a writer for a specific log format
31 (JSON, XML, traditional MySQL, etc.), it may implement a filter that
32 removes or modifies log_items, etc.
33*/
34
35#ifndef LOG_SERVICE_H
36#define LOG_SERVICE_H
37
42
43/* service helpers */
45 /** We do not have information about this service yet. */
47
48 /** Service is read-only -- it guarantees it will not modify the log-event.
49 This information may later be used to e.g. run log-writers in parallel. */
51
52 /** Service is a singleton -- it may occur in the log service pipeline
53 only once. */
55
56 /** Service is built-in (and can not be INSTALLed/UNINSTALLed */
58
59 // values from 8..64 are reserved for extensions
60
61 /** Service is a source. It adds key/value pairs beyond those in the
62 statement that first created the log-event. Log-sources are not
63 normally READ_ONLY. */
65
66 /** Service is a filter. A filter should not be the last service in
67 the log service pipeline. */
69
70 /** Service is a sink (usually a log-writer). Sinks will normally
71 not modify the log-event, but be READ_ONLY. */
73
74 /** Service supports the performance_schema.error_log table.
75 If the caller provides a buffer, the service will write output
76 to be displayed in the performance-schema table there.
77 This can be the entirety of the log-entry, or a projection
78 thereof (usually omitting key/value pairs that are already
79 shown in other columns of said table).
80 Services flagged this must also be flagged LOG_SERVICE_SINK! */
82
83 /** Service can parse lines in the format it outputs. Services flagged
84 this must also be flagged LOG_SERVICE_SINK | LOG_SERVICE_PFS_SUPPORT! */
87
88/**
89 Error codes. These are grouped (general issues, invalid data,
90 file ops, etc.). Each group has a sparsely populated range so
91 we may add entries as needed without introducing incompatibility
92 by renumbering the existing ones.
93*/
95 /// no error
97
98 /// error not otherwise specified
100
101 /// no error, but no effect either
103
104 /**
105 arguments are valid, we just don't have the space (either pre-allocated
106 in this function, or passed to us by the caller)
107 */
109
110 /// we cannot allocate a (temporary or return) buffer of the required size
112
113 /// service uninavailable (bad internal state/underlying service unavailable)
115
116 /// for a method with modes, a mode unsupported by this service was requested
118
119 /// argument was invalid (out of range, malformed, etc.)
121
122 /**
123 argument too long (a special case of malformed).
124 E.g. a path longer than FN_REFLEN, or a presumed data longer than
125 specified in ISO-8601.
126 use LOG_SERVICE_INVALID_ARGUMENT, LOG_SERVICE_BUFFER_SIZE_INSUFFICIENT,
127 or LOG_SERVICE_OUT_OF_MEMORY if more appropriate.
128 */
130
131 /**
132 invalid data, but not arguments to a C++ function
133 (bad log-file to parse, filter language statement, etc.)
134 */
136
137 /// could not make log name
139
140 /// lock error (could not init, or is not inited, etc.)
142
143 /// can not write
149
150 /// no more instances of this service are possible.
153
155/**
156 Have the service process one log line.
157
158 @param instance State-pointer that was returned on open.
159 @param ll The log_line collection of log_items.
160
161 @retval <0 an error occurred
162 @retval =0 no work was done
163 @retval >0 number of processed entities
164*/
165DECLARE_METHOD(int, run, (void *instance, log_line *ll));
166
167/**
168 Flush any buffers. This function will be called by the server
169 on FLUSH ERROR LOGS. The service may write its buffers, close
170 and re-open any log files to work with log-rotation, etc.
171 The flush function MUST NOT itself log anything (as the caller
172 holds THR_LOCK_log_stack)!
173 A service implementation may provide a nullptr if it does not
174 wish to provide a flush function.
175
176 @param instance State-pointer that was returned on open.
177 Value may be changed in flush.
178
179 @returns LOG_SERVICE_NOTHING_DONE no work was done
180 @returns LOG_SERVICE_SUCCESS flush completed without incident
181 @returns otherwise an error occurred
182*/
184
185/**
186 Open a new instance.
187
188 @param ll optional arguments
189 @param instance If state is needed, the service may allocate and
190 initialize it and return a pointer to it here.
191 (This of course is particularly pertinent to
192 components that may be opened multiple times,
193 such as the JSON log writer.)
194 This state is for use of the log-service component
195 in question only and can take any layout suitable
196 to that component's need. The state is opaque to
197 the server/logging framework. It must be released
198 on close.
199
200 @returns LOG_SERVICE_SUCCESS success, returned handle is valid
201 @returns otherwise a new instance could not be created
202*/
204
205/**
206 Close and release an instance. Flushes any buffers.
207
208 @param instance State-pointer that was returned on open.
209 If memory was allocated for this state,
210 it should be released, and the pointer
211 set to nullptr.
212
213 @returns LOG_SERVICE_SUCCESS success
214 @returns otherwise an error occurred
215*/
217
218/**
219 Get characteristics of a log-service.
220
221 @retval <0 an error occurred
222 @retval >=0 characteristics (a set of log_service_chistics flags)
223*/
224DECLARE_METHOD(int, characteristics, (void));
225
226/**
227 Parse a single line in an error log of this format. (optional)
228
229 @param line_start pointer to the beginning of the line ('{')
230 @param line_length length of the line
231
232 @retval 0 Success
233 @retval !=0 Failure (out of memory, malformed argument, etc.)
234*/
235DECLARE_METHOD(log_service_error, parse_log_line,
236 (const char *line_start, size_t line_length));
237
238/**
239 Provide the name for a log file this service would access.
240
241 @param instance instance info returned by open() if requesting
242 the file-name for a specific open instance.
243 nullptr to get the name of the default instance
244 (even if it that log is not open). This is used
245 to determine the name of the log-file to load on
246 start-up.
247 @param buf Address of a buffer allocated in the caller.
248 The callee may return an extension starting
249 with '.', in which case the path and file-name
250 will be the system's default, except with the
251 given extension.
252 Alternatively, the callee may return a file-name
253 which is assumed to be in the same directory
254 as the default log.
255 Values are C-strings.
256 @param bufsize The size of the allocation in the caller.
257
258 @retval 0 Success
259 @retval -1 Mode not supported (only default / only instances supported)
260 @retval -2 Buffer not large enough
261 @retval -3 Misc. error
262*/
264 (void *instance, char *buf, size_t bufsize));
265
267
268#endif
Specifies macros to define Components.
static void run(mysql_harness::PluginFuncEnv *)
Definition: io_plugin.cc:199
enum enum_log_service_error log_service_error
Error codes.
enum enum_log_service_chistics log_service_chistics
This defines the API used to call functions in logging components.
enum_log_service_chistics
This defines the API used to call functions in logging components.
Definition: log_service.h:44
@ LOG_SERVICE_SINK
Service is a sink (usually a log-writer).
Definition: log_service.h:72
@ LOG_SERVICE_LOG_PARSER
Service can parse lines in the format it outputs.
Definition: log_service.h:85
@ LOG_SERVICE_UNSPECIFIED
We do not have information about this service yet.
Definition: log_service.h:46
@ LOG_SERVICE_READ_ONLY
Service is read-only – it guarantees it will not modify the log-event.
Definition: log_service.h:50
@ LOG_SERVICE_SOURCE
Service is a source.
Definition: log_service.h:64
@ LOG_SERVICE_SINGLETON
Service is a singleton – it may occur in the log service pipeline only once.
Definition: log_service.h:54
@ LOG_SERVICE_BUILTIN
Service is built-in (and can not be INSTALLed/UNINSTALLed.
Definition: log_service.h:57
@ LOG_SERVICE_PFS_SUPPORT
Service supports the performance_schema.error_log table.
Definition: log_service.h:81
@ LOG_SERVICE_FILTER
Service is a filter.
Definition: log_service.h:68
enum_log_service_error
Error codes.
Definition: log_service.h:94
@ LOG_SERVICE_BUFFER_SIZE_INSUFFICIENT
arguments are valid, we just don't have the space (either pre-allocated in this function,...
Definition: log_service.h:108
@ LOG_SERVICE_LOCK_ERROR
lock error (could not init, or is not inited, etc.)
Definition: log_service.h:141
@ LOG_SERVICE_OPEN_FAILED
Definition: log_service.h:146
@ LOG_SERVICE_UNSUPPORTED_MODE
for a method with modes, a mode unsupported by this service was requested
Definition: log_service.h:117
@ LOG_SERVICE_UNABLE_TO_READ
Definition: log_service.h:145
@ LOG_SERVICE_PARSE_ERROR
invalid data, but not arguments to a C++ function (bad log-file to parse, filter language statement,...
Definition: log_service.h:135
@ LOG_SERVICE_TOO_MANY_INSTANCES
no more instances of this service are possible.
Definition: log_service.h:151
@ LOG_SERVICE_SEEK_FAILED
Definition: log_service.h:148
@ LOG_SERVICE_ARGUMENT_TOO_LONG
argument too long (a special case of malformed).
Definition: log_service.h:129
@ LOG_SERVICE_CLOSE_FAILED
Definition: log_service.h:147
@ LOG_SERVICE_NOT_AVAILABLE
service uninavailable (bad internal state/underlying service unavailable)
Definition: log_service.h:114
@ LOG_SERVICE_MISC_ERROR
error not otherwise specified
Definition: log_service.h:99
@ LOG_SERVICE_COULD_NOT_MAKE_LOG_NAME
could not make log name
Definition: log_service.h:138
@ LOG_SERVICE_OUT_OF_MEMORY
we cannot allocate a (temporary or return) buffer of the required size
Definition: log_service.h:111
@ LOG_SERVICE_INVALID_ARGUMENT
argument was invalid (out of range, malformed, etc.)
Definition: log_service.h:120
@ LOG_SERVICE_SUCCESS
no error
Definition: log_service.h:96
@ LOG_SERVICE_NOTHING_DONE
no error, but no effect either
Definition: log_service.h:102
@ LOG_SERVICE_UNABLE_TO_WRITE
can not write
Definition: log_service.h:144
Definition: buf0block_hint.cc:30
stdx::expected< void, std::error_code > close(file_handle_type native_handle)
close file handle.
Definition: file.h:239
static mysql_service_status_t flush(reference_caching_cache cache) noexcept
Definition: component.cc:114
stdx::expected< int, std::error_code > open(const char *fname, int flags, mode_t mode) noexcept
Definition: file_handle.cc:79
#define DECLARE_METHOD(retval, name, args)
Declares a method as a part of the Service definition.
Definition: service.h:103
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
Specifies macros to define Service Implementations.
log_line ("log event")
Definition: keyring_log_builtins_definition.cc:72