MySQL 8.0.29
Source Code Documentation
log_builtins.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/**
24 This defines built-in functions for use by logging services.
25 These helpers are organized into a number of APIs grouping
26 related functionality.
27
28 For documentation of the individual functions, see log_builtins.cc
29*/
30
31#ifndef LOG_BUILTINS_H
32#define LOG_BUILTINS_H
33
39#if defined(MYSQL_DYNAMIC_PLUGIN)
41#endif
42#include <stdarg.h>
43#include <stdio.h>
44#include <string.h>
45
46#include <my_compiler.h>
47#if defined(MYSQL_SERVER) && !defined(MYSQL_DYNAMIC_PLUGIN)
48#include "sql/log.h"
49#endif
50
51/**
52 Primitives for services to interact with the structured logger:
53 functions pertaining to log_line and log_item data
54*/
56/**
57 See whether a type is wellknown.
58
59 @param t log item type to examine
60
61 @retval LOG_ITEM_TYPE_NOT_FOUND: key not found
62 @retval >0: index in array of wellknowns
63*/
64DECLARE_METHOD(int, wellknown_by_type, (log_item_type t));
65
66/**
67 See whether a string is a wellknown field name.
68
69 @param key potential key starts here
70 @param length length of the string to examine
71
72 @retval LOG_ITEM_TYPE_RESERVED: reserved, but not "wellknown" key
73 @retval LOG_ITEM_TYPE_NOT_FOUND: key not found
74 @retval >0: index in array of wellknowns
75*/
76DECLARE_METHOD(int, wellknown_by_name, (const char *key, size_t length));
77
78/**
79 Accessor: from a record describing a wellknown key, get its type
80
81 @param idx index in array of wellknowns, see log_item_wellknown_by_...()
82
83 @retval the log item type for the wellknown key
84*/
85DECLARE_METHOD(log_item_type, wellknown_get_type, (uint idx));
86
87/**
88 Accessor: from a record describing a wellknown key, get its name
89
90 @param idx index in array of wellknowns, see log_item_wellknown_by_...()
91
92 @retval name (NTBS)
93*/
94DECLARE_METHOD(const char *, wellknown_get_name, (uint idx));
95
96/**
97 Sanity check an item.
98 Certain log sinks have very low requirements with regard to the data
99 they receive; they write keys as strings, and then data according to
100 the item's class (string, integer, or float), formatted to the sink's
101 standards (e.g. JSON, XML, ...).
102 Code that has higher requirements can use this check to see whether
103 the given item is of a known type (whether generic or wellknown),
104 whether the given type and class agree, and whether in case of a
105 well-known type, the given key is correct for that type.
106 If your code generates items that don't pass this check, you should
107 probably go meditate on it.
108
109 @param li the log_item to check
110
111 @retval LOG_ITEM_OK no problems
112 @retval LOG_ITEM_TYPE_NOT_FOUND unknown item type
113 @retval LOG_ITEM_CLASS_MISMATCH item_class derived from type isn't
114 what's set on the item
115 @retval LOG_ITEM_KEY_MISMATCH class not generic, so key should
116 match wellknown
117 @retval LOG_ITEM_STRING_NULL class is string, pointer is nullptr
118 @retval LOG_ITEM_KEY_NULL no key set (this is legal e.g. on aux
119 items of filter rules, but should not
120 occur in a log_line, i.e., log_sinks are
121 within their rights to discard such items)
122*/
123DECLARE_METHOD(int, item_inconsistent, (log_item * li));
124
125// helpers: predicates to find out about types and classes
126
127/**
128 Predicate used to determine whether a type is generic
129 (generic string, generic float, generic integer) rather
130 than a well-known type.
131
132 @param t log item type to examine
133
134 @retval true if generic type
135 @retval false if wellknown type
136*/
137DECLARE_METHOD(bool, item_generic_type, (log_item_type t));
138
139/**
140 Predicate used to determine whether a class is a string
141 class (C-string or Lex-string).
142
143 @param c log item class to examine
144
145 @retval true if of a string class
146 @retval false if not of a string class
147*/
148DECLARE_METHOD(bool, item_string_class, (log_item_class c));
149
150/**
151 Predicate used to determine whether a class is a numeric
152 class (integer or float).
153
154 @param c log item class to examine
155
156 @retval true if of a numeric class
157 @retval false if not of a numeric class
158*/
159DECLARE_METHOD(bool, item_numeric_class, (log_item_class c));
160
161/**
162 Set an integer value on a log_item.
163 Fails gracefully if no log_item_data is supplied, so it can safely
164 wrap log_line_item_set[_with_key]().
165
166 @param lid log_item_data struct to set the value on
167 @param i integer to set
168
169 @retval true lid was nullptr (possibly: OOM, could not set up log_item)
170 @retval false all's well
171*/
172DECLARE_METHOD(bool, item_set_int, (log_item_data * lid, longlong i));
173/**
174 Set a floating point value on a log_item.
175 Fails gracefully if no log_item_data is supplied, so it can safely
176 wrap log_line_item_set[_with_key]().
177
178 @param lid log_item_data struct to set the value on
179 @param f float to set
180
181 @retval true lid was nullptr (possibly: OOM, could not set up log_item)
182 @retval false all's well
183*/
184DECLARE_METHOD(bool, item_set_float, (log_item_data * lid, double f));
185
186/**
187 Set a string value on a log_item.
188 Fails gracefully if no log_item_data is supplied, so it can safely
189 wrap log_line_item_set[_with_key]().
190
191 @param lid log_item_data struct to set the value on
192 @param s pointer to string
193 @param s_len length of string
194
195 @retval true lid was nullptr (possibly: OOM, could not set up log_item)
196 @retval false all's well
197*/
198DECLARE_METHOD(bool, item_set_lexstring,
199 (log_item_data * lid, const char *s, size_t s_len));
200
201/**
202 Set a string value on a log_item.
203 Fails gracefully if no log_item_data is supplied, so it can safely
204 wrap log_line_item_set[_with_key]().
205
206 @param lid log_item_data struct to set the value on
207 @param s pointer to NTBS
208
209 @retval true lid was nullptr (possibly: OOM, could not set up log_item)
210 @retval false all's well
211*/
212DECLARE_METHOD(bool, item_set_cstring, (log_item_data * lid, const char *s));
213
214/**
215 Create new log item with key name "key", and allocation flags of
216 "alloc" (see enum_log_item_free).
217 Will return a pointer to the item's log_item_data struct for
218 convenience.
219 This is mostly interesting for filters and other services that create
220 items that are not part of a log_line; sources etc. that intend to
221 create an item for a log_line (the more common case) should usually
222 use the below line_item_set_with_key() which creates an item (like
223 this function does), but also correctly inserts it into a log_line.
224
225 @param li the log_item to work on
226 @param t the item-type
227 @param key the key to set on the item.
228 ignored for non-generic types (may pass nullptr for those)
229 see alloc
230 @param alloc LOG_ITEM_FREE_KEY if key was allocated by caller
231 LOG_ITEM_FREE_NONE if key was not allocated
232 Allocated keys will automatically free()d when the
233 log_item is.
234 The log_item's alloc flags will be set to the
235 submitted value; specifically, any pre-existing
236 value will be clobbered. It is therefore WRONG
237 a) to use this on a log_item that already has a key;
238 it should only be used on freshly init'd log_items;
239 b) to use this on a log_item that already has a
240 value (specifically, an allocated one); the correct
241 order is to init a log_item, then set up type and
242 key, and finally to set the value. If said value is
243 an allocated string, the log_item's alloc should be
244 bitwise or'd with LOG_ITEM_FREE_VALUE.
245
246 @retval a pointer to the log_item's log_data, for easy chaining:
247 log_item_set_with_key(...)->data_integer= 1;
248*/
249DECLARE_METHOD(log_item_data *, item_set_with_key,
250 (log_item * li, log_item_type t, const char *key, uint32 alloc));
251
252/**
253 As log_item_set_with_key(), except that the key is automatically
254 derived from the wellknown log_item_type t.
255
256 Create new log item with type "t".
257 Will return a pointer to the item's log_item_data struct for
258 convenience.
259 This is mostly interesting for filters and other services that create
260 items that are not part of a log_line; sources etc. that intend to
261 create an item for a log_line (the more common case) should usually
262 use the below line_item_set_with_key() which creates an item (like
263 this function does), but also correctly inserts it into a log_line.
264
265 The allocation of this item will be LOG_ITEM_FREE_NONE;
266 specifically, any pre-existing value will be clobbered.
267 It is therefore WRONG
268 a) to use this on a log_item that already has a key;
269 it should only be used on freshly init'd log_items;
270 b) to use this on a log_item that already has a
271 value (specifically, an allocated one); the correct
272 order is to init a log_item, then set up type and
273 key, and finally to set the value. If said value is
274 an allocated string, the log_item's alloc should be
275 bitwise or'd with LOG_ITEM_FREE_VALUE.
276
277 @param li the log_item to work on
278 @param t the item-type
279
280 @retval a pointer to the log_item's log_data, for easy chaining:
281 log_item_set_with_key(...)->data_integer= 1;
282*/
284
285/**
286 Create new log item in log line "ll", with key name "key", and
287 allocation flags of "alloc" (see enum_log_item_free).
288 On success, the number of registered items on the log line is increased,
289 the item's type is added to the log_line's "seen" property,
290 and a pointer to the item's log_item_data struct is returned for
291 convenience.
292
293 @param ll the log_line to work on
294 @param t the item-type
295 @param key the key to set on the item.
296 ignored for non-generic types (may pass nullptr for those)
297 see alloc
298 @param alloc LOG_ITEM_FREE_KEY if key was allocated by caller
299 LOG_ITEM_FREE_NONE if key was not allocated
300 Allocated keys will automatically free()d when the
301 log_item is.
302 The log_item's alloc flags will be set to the
303 submitted value; specifically, any pre-existing
304 value will be clobbered. It is therefore WRONG
305 a) to use this on a log_item that already has a key;
306 it should only be used on freshly init'd log_items;
307 b) to use this on a log_item that already has a
308 value (specifically, an allocated one); the correct
309 order is to init a log_item, then set up type and
310 key, and finally to set the value. If said value is
311 an allocated string, the log_item's alloc should be
312 bitwise or'd with LOG_ITEM_FREE_VALUE.
313
314 @retval a pointer to the log_item's log_data, for easy chaining:
315 log_line_item_set_with_key(...)->data_integer= 1;
316*/
317DECLARE_METHOD(log_item_data *, line_item_set_with_key,
318 (log_line * ll, log_item_type t, const char *key, uint32 alloc));
319
320/**
321 Create a new log item of well-known type "t" in log line "ll".
322 On success, the number of registered items on the log line is increased,
323 the item's type is added to the log_line's "seen" property,
324 and a pointer to the item's log_item_data struct is returned for
325 convenience.
326
327 The allocation of this item will be LOG_ITEM_FREE_NONE;
328 specifically, any pre-existing value will be clobbered.
329 It is therefore WRONG
330 a) to use this on a log_item that already has a key;
331 it should only be used on freshly init'd log_items;
332 b) to use this on a log_item that already has a
333 value (specifically, an allocated one); the correct
334 order is to init a log_item, then set up type and
335 key, and finally to set the value. If said value is
336 an allocated string, the log_item's alloc should be
337 bitwise or'd with LOG_ITEM_FREE_VALUE.
338
339 @param ll the log_line to work on
340 @param t the item-type
341
342 @retval a pointer to the log_item's log_data, for easy chaining:
343 log_line_item_set_with_key(...)->data_integer= 1;
344*/
345DECLARE_METHOD(log_item_data *, line_item_set,
347
348/**
349 Dynamically allocate and initialize a log_line.
350
351 @retval nullptr could not set up buffer (too small?)
352 @retval other address of the newly initialized log_line
353*/
354DECLARE_METHOD(log_line *, line_init, ());
355
356/**
357 Release a log_line allocated with line_init()
358
359 @param ll a log_line previously allocated with line_init()
360*/
361DECLARE_METHOD(void, line_exit, (log_line * ll));
362
363/**
364 How many items are currently set on the given log_line?
365
366 @param ll the log-line to examine
367
368 @retval the number of items set
369*/
370DECLARE_METHOD(int, line_item_count, (log_line * ll));
371
372/**
373 Test whether a given type is presumed present on the log line.
374
375 @param ll the log_line to examine
376 @param m the log_type to test for
377
378 @retval 0 not present
379 @retval !=0 present
380*/
381DECLARE_METHOD(log_item_type_mask, line_item_types_seen,
383
384/**
385 Get log-line's output buffer.
386 If the logger core provides this buffer, the log-service may use it
387 to assemble its output therein and implicitly return it to the core.
388 Participation is required for services that support populating
389 performance_schema.error_log, and optional for all others.
390
391 @param ll the log_line to examine
392
393 @retval nullptr success, an output buffer is available
394 @retval otherwise failure, no output buffer is available
395*/
396DECLARE_METHOD(log_item *, line_get_output_buffer, (log_line * ll));
397
398/**
399 Get an iterator for the items in a log_line.
400 For now, only one iterator may exist per log_line.
401
402 @param ll the log_line to examine
403
404 @retval a log_iter_iter, or nullptr on failure
405*/
406DECLARE_METHOD(log_item_iter *, line_item_iter_acquire, (log_line * ll));
407
408/**
409 Release an iterator for the items in a log_line.
410
411 @param it the iterator to release
412*/
413DECLARE_METHOD(void, line_item_iter_release, (log_item_iter * it));
414/**
415 Use the log_line iterator to get the first item from the set.
416
417 @param it the iterator to use
418
419 @retval pointer to the first log_item in the collection, or nullptr
420*/
421DECLARE_METHOD(log_item *, line_item_iter_first, (log_item_iter * it));
422
423/**
424 Use the log_line iterator to get the next item from the set.
425
426 @param it the iterator to use
427
428 @retval pointer to the next log_item in the collection, or nullptr
429*/
430DECLARE_METHOD(log_item *, line_item_iter_next, (log_item_iter * it));
431
432/**
433 Use the log_line iterator to get the current item from the set.
434
435 @param it the iterator to use
436
437 @retval pointer to the current log_item in the collection, or nullptr
438*/
439DECLARE_METHOD(log_item *, line_item_iter_current, (log_item_iter * it));
440
441/**
442 Complete, filter, and write submitted log items.
443
444 This expects a log_line collection of log-related key/value pairs,
445 e.g. from log_message().
446
447 Where missing, timestamp, priority, thread-ID (if any) and so forth
448 are added.
449
450 Log item source services, log item filters, and log item sinks are
451 then called; then all applicable resources are freed.
452
453 This interface is intended to facilitate the building of submission
454 interfaces other than the variadic message() one below. See the
455 example fluent C++ LogEvent() wrapper for an example of how to leverage
456 it.
457
458 @param ll key/value pairs describing info to log
459
460 @retval int number of fields in created log line
461*/
462DECLARE_METHOD(int, line_submit, (log_line * ll));
463
464/**
465 Submit a log-message for log "log_type".
466 Variadic convenience function for logging.
467
468 This fills in the array that is used by the filter and log-writer
469 services. Where missing, timestamp, priority, and thread-ID (if any)
470 are added. Log item source services, log item filters, and log item
471 writers are called.
472
473
474 The variadic list accepts a list of "assignments" of the form
475 - log_item_type, value, for well-known types, and
476 - log_item_type, key, value, for ad-hoc types (LOG_ITEM_GEN_*)
477
478 As its last item, the list should have
479 - an element of type LOG_ITEM_LOG_MESSAGE, containing a printf-style
480 format string, followed by all variables necessary to satisfy the
481 substitutions in that string
482
483 OR
484
485 - an element of type LOG_ITEM_LOG_LOOKUP, containing a MySQL error code,
486 which will be looked up in the list or regular error messages, followed
487 by all variables necessary to satisfy the substitutions in that string
488
489 OR
490
491 - an element of type LOG_ITEM_LOG_VERBATIM, containing a string that will
492 be used directly, with no % substitutions
493
494 see log_vmessage() for more information.
495*/
496DECLARE_METHOD(int, message, (int log_type, ...));
497
498/**
499 Escape \0 bytes, add \0 terminator. For log-writers and other sinks
500 that terminate in an API using C-strings.
501
502
503 @param li list_item to process
504
505 @retval -1 out of memory
506 @retval 0 success
507*/
508DECLARE_METHOD(int, sanitize, (log_item * li));
509
510/**
511 Return MySQL error message for a given error code.
512
513 @param mysql_errcode the error code the message for which to look up
514
515 @retval the message (a printf-style format string)
516*/
517DECLARE_METHOD(const char *, errmsg_by_errcode, (int mysql_errcode));
518
519/**
520 Return MySQL error code for a given error symbol.
521
522 @param sym the symbol to look up
523
524 @retval -1 failure
525 @retval >=0 the MySQL error code
526*/
527DECLARE_METHOD(longlong, errcode_by_errsymbol, (const char *sym));
528
529/**
530 Convenience function: Derive a log label ("error", "warning",
531 "information") from a severity.
532
533 @param prio the severity/prio in question
534
535 @return a label corresponding to that priority.
536 @retval "System" for prio of SYSTEM_LEVEL
537 @retval "Error" for prio of ERROR_LEVEL
538 @retval "Warning" for prio of WARNING_LEVEL
539 @retval "Note" for prio of INFORMATION_LEVEL
540*/
541DECLARE_METHOD(const char *, label_from_prio, (int prio));
542
543/**
544 Parse a ISO8601 timestamp and return the number of microseconds
545 since the epoch. Heeds +/- timezone info if present.
546
547 @see make_iso8601_timestamp()
548
549 @param timestamp an ASCII string containing an ISO8601 timestamp
550 @param len Length in bytes of the aforementioned string
551
552 @return microseconds since the epoch
553*/
554DECLARE_METHOD(ulonglong, parse_iso8601_timestamp,
555 (const char *timestamp, size_t len));
556
557/**
558 open an error log file
559
560 @param name_or_ext if beginning with '.':
561 @@global.log_error, except with this extension
562 otherwise:
563 use this as file name in the same location as
564 @@global.log_error
565
566 Value not contain folder separators!
567
568 @param[out] my_errstream an error log handle, or nullptr on failure
569
570 @returns LOG_SERVICE_SUCCESS success
571 @returns LOG_SERVICE_INVALID_ARGUMENT no my_errstream, or bad log name
572 @returns LOG_SERVICE_OUT_OF_MEMORY could not allocate file handle
573 @returns LOG_SERVICE_LOCK_ERROR couldn't lock lock
574 @returns LOG_SERVICE_UNABLE_TO_WRITE couldn't write to given location
575 @returns LOG_SERVICE_COULD_NOT_MAKE_LOG_NAME could not make log name
576*/
577DECLARE_METHOD(log_service_error, open_errstream,
578 (const char *name_or_ext, void **my_errstream));
579
580/**
581 write to an error log file previously opened with open_errstream()
582
583 @param my_errstream a handle describing the log file
584 @param buffer pointer to the string to write
585 @param length length of the string to write
586
587 @returns LOG_SERVICE_SUCCESS success
588 @returns otherwise failure
589*/
590DECLARE_METHOD(log_service_error, write_errstream,
591 (void *my_errstream, const char *buffer, size_t length));
592
593/**
594 are we writing to a dedicated errstream, or are we sharing it?
595
596 @param my_errstream a handle describing the log file
597
598 @retval 0 not dedicated (multiplexed, stderr, ...)
599 @retval 1 dedicated
600*/
601DECLARE_METHOD(int, dedicated_errstream, (void *my_errstream));
602
603/**
604 close an error log file previously opened with open_errstream()
605
606 @param my_stream a handle describing the log file
607
608 @returns LOG_SERVICE_SUCCESS on success
609*/
610DECLARE_METHOD(log_service_error, close_errstream, (void **my_errstream));
611
612/**
613 re-open an error log file
614 (primarily to facilitate flush/log-rotation)
615
616 If the new file can be opened, update the my_errstream descriptor to
617 use it and close the old file. Otherwise, keep using the old file.
618
619 @param name_or_ext if beginning with '.':
620 @@global.log_error, except with this extension
621 otherwise:
622 use this as file name in the same location as
623 @@global.log_error
624
625 Value may not contain folder separators!
626
627 In the general case, the caller will be a
628 log-writer, the log-writer will just pass
629 its preferred file extension, and the resulting
630 file name and path will therefore be the same
631 as for the original log file.
632
633 @param[in,out] my_errstream an error log handle
634
635 @returns LOG_SERVICE_INVALID_ARGUMENT, or the result of open_errstream()
636*/
637DECLARE_METHOD(log_service_error, reopen_errstream,
638 (const char *file, void **my_errstream));
639
641
642/**
643 String primitives for logging services.
644*/
645BEGIN_SERVICE_DEFINITION(log_builtins_string)
646// alloc (len+1) bytes
647DECLARE_METHOD(void *, malloc, (size_t len));
648// alloc (len+1) bytes, then copy len bytes from fm, and \0 terminate
649// like my_strndup(), and unlike strndup(), \0 in input won't end copying
650DECLARE_METHOD(char *, strndup, (const char *fm, size_t len));
651// free allocated memory
652DECLARE_METHOD(void, free, (void *ptr));
653
654// length of nul terminated byte string
655DECLARE_METHOD(size_t, length, (const char *s));
656// find char in string, from the left
657DECLARE_METHOD(char *, find_first, (const char *s, int c));
658// find char in string, from the right
659DECLARE_METHOD(char *, find_last, (const char *s, int c));
660
661// compare two NUL-terminated byte-strings
663 (const char *a, const char *b, size_t len,
664 bool case_insensitive));
665
666/**
667 Wrapper for std::snprintf()
668 Replace all % in format string with variables from list.
669 Do not use in new code; use std::snprintf() instead.
670
671 @param to buffer to write the result to
672 @param n size of that buffer
673 @param fmt format string
674 @param ap va_list with valuables for all substitutions in format string
675
676 @retval return value of snprintf
677*/
678DECLARE_METHOD(size_t, substitutev,
679 (char *to, size_t n, const char *fmt, va_list ap))
680MY_ATTRIBUTE((format(printf, 3, 0)));
681
682// replace all % in format string with variables from list (std::snprintf())
683DECLARE_METHOD(size_t, substitute, (char *to, size_t n, const char *fmt, ...))
684MY_ATTRIBUTE((format(printf, 3, 4)));
685
686END_SERVICE_DEFINITION(log_builtins_string)
687
688/**
689 Temporary primitives for logging services.
690*/
692// Are we shutting down yet? Windows EventLog needs to know.
693DECLARE_METHOD(size_t, notify_client,
694 (void *thd, uint severity, uint code, char *to, size_t n,
695 const char *format, ...))
696MY_ATTRIBUTE((format(printf, 6, 7)));
697END_SERVICE_DEFINITION(log_builtins_tmp)
698
699/**
700 Syslog/Eventlog functions for logging services.
701*/
702BEGIN_SERVICE_DEFINITION(log_builtins_syseventlog)
704 (const char *name, int option, int facility));
706 (enum loglevel level, const char *msg));
708END_SERVICE_DEFINITION(log_builtins_syseventlog)
709
710#ifdef __cplusplus
711
712#if !defined(LOG_H)
713
714extern SERVICE_TYPE(log_builtins) * log_bi;
715extern SERVICE_TYPE(log_builtins_string) * log_bs;
716
717#define log_line_init log_bi->line_init
718#define log_line_exit log_bi->line_exit
719#define log_line_item_set_with_key log_bi->line_item_set_with_key
720#define log_line_item_set log_bi->line_item_set
721#define log_line_item_types_seen log_bi->line_item_types_seen
722#define log_line_submit log_bi->line_submit
723#define log_set_int log_bi->item_set_int
724#define log_set_float log_bi->item_set_float
725#define log_set_lexstring log_bi->item_set_lexstring
726#define log_set_cstring log_bi->item_set_cstring
727#define log_malloc log_bs->malloc
728#define log_free log_bs->free
729#define log_msg log_bs->substitutev
730#define error_msg_by_errcode log_bi->errmsg_by_errcode
731#define error_code_by_errsymbol log_bi->errcode_by_errsymbol
732#else
733
734#include "sql/derror.h"
735
736#define log_malloc(s) my_malloc(0, (s), MYF(0))
737#define log_free my_free
738#define log_msg vsnprintf
739#define error_msg_by_errcode error_message_for_error_log
740#define error_code_by_errsymbol mysql_symbol_to_errno
741#define log_set_int log_item_set_int
742#define log_set_float log_item_set_float
743#define log_set_lexstring log_item_set_lexstring
744#define log_set_cstring log_item_set_cstring
745
746/**
747 Very long-running functions during server start-up can use this
748 function to check whether the time-out for buffered logging has
749 been reached. If so and we have urgent information, all buffered
750 log events will be flushed to the log using built-in default-logger
751 for the time being. The information will be kept until start-up
752 completes in case it later turns out the user configured a loadable
753 logger, in which case we'll also flush the buffered information to
754 that logger later once the logger becomes available.
755
756 This function should only be used during start-up; once external
757 components are loaded by the component framework, this function
758 should no longer be called (as log events are no longer buffered,
759 but logged immediately).
760*/
762#endif // LOG_H
763
764#ifndef DISABLE_ERROR_LOGGING
765
766#if defined(LOG_COMPONENT_TAG)
767
768#define LogErr(severity, ecode, ...) \
769 LogEvent() \
770 .prio(severity) \
771 .errcode(ecode) \
772 .subsys(LOG_SUBSYSTEM_TAG) \
773 .component(LOG_COMPONENT_TAG) \
774 .source_line(__LINE__) \
775 .source_file(MY_BASENAME) \
776 .function(__FUNCTION__) \
777 .lookup(ecode, ##__VA_ARGS__)
778
779#define LogComponentErr(severity, ecode, ...) \
780 LogEvent() \
781 .prio(severity) \
782 .errcode(ecode) \
783 .subsys(LOG_SUBSYSTEM_TAG) \
784 .component("component:" LOG_COMPONENT_TAG) \
785 .source_line(__LINE__) \
786 .source_file(MY_BASENAME) \
787 .function(__FUNCTION__) \
788 .lookup_quoted(ecode, "Component " LOG_COMPONENT_TAG " reported", \
789 ##__VA_ARGS__)
790
791#define LogPluginErr(severity, ecode, ...) \
792 LogEvent() \
793 .prio(severity) \
794 .errcode(ecode) \
795 .subsys(LOG_SUBSYSTEM_TAG) \
796 .component("plugin:" LOG_COMPONENT_TAG) \
797 .source_line(__LINE__) \
798 .source_file(MY_BASENAME) \
799 .function(__FUNCTION__) \
800 .lookup_quoted(ecode, "Plugin " LOG_COMPONENT_TAG " reported", \
801 ##__VA_ARGS__)
802
803#define LogPluginErrV(severity, ecode, vl) \
804 LogEvent() \
805 .prio(severity) \
806 .errcode(ecode) \
807 .subsys(LOG_SUBSYSTEM_TAG) \
808 .component("plugin:" LOG_COMPONENT_TAG) \
809 .source_line(__LINE__) \
810 .source_file(MY_BASENAME) \
811 .function(__FUNCTION__) \
812 .lookup_quotedv(ecode, "Plugin " LOG_COMPONENT_TAG " reported", vl)
813
814#define LogPluginErrMsg(severity, ecode, ...) \
815 LogEvent() \
816 .prio(severity) \
817 .errcode(ecode) \
818 .subsys(LOG_SUBSYSTEM_TAG) \
819 .component("plugin:" LOG_COMPONENT_TAG) \
820 .source_line(__LINE__) \
821 .source_file(MY_BASENAME) \
822 .function(__FUNCTION__) \
823 .message_quoted("Plugin " LOG_COMPONENT_TAG " reported", ##__VA_ARGS__)
824
825#else
826
827#define LogErr(severity, ecode, ...) \
828 LogEvent() \
829 .prio(severity) \
830 .errcode(ecode) \
831 .subsys(LOG_SUBSYSTEM_TAG) \
832 .source_line(__LINE__) \
833 .source_file(MY_BASENAME) \
834 .function(__FUNCTION__) \
835 .lookup(ecode, ##__VA_ARGS__)
836
837#endif
838
839#else
840
841inline void dummy_log_message(longlong severity [[maybe_unused]],
842 longlong ecode [[maybe_unused]], ...) {
843 return;
844}
845
846#define LogErr(severity, ecode, ...) \
847 dummy_log_message(severity, ecode, ##__VA_ARGS__)
848
849#define LogPluginErr(severity, ecode, ...) \
850 dummy_log_message(severity, ecode, ##__VA_ARGS__)
851#define LogPluginErrV(severity, ecode, ...) \
852 dummy_log_message(severity, ecode, ##__VA_ARGS__)
853#define LogPluginErrMsg(severity, ecode, ...) \
854 dummy_log_message(severity, ecode, ##__VA_ARGS__)
855
856#endif // DISABLE_ERROR_LOGGING
857
858/**
859 Modular logger: fluid API. Server-internal. Lets you use safe and
860 expressive syntax, like so:
861
862 LogEvent(LOG_TYPE_ERROR).prio(INFORMATION_LEVEL).message("Meow! %d", 4711);
863*/
864
865class LogEvent {
866 private:
868 char *msg;
869 const char *msg_tag;
870
871 /**
872 Set MySQL error-code if none has been set yet.
873
874 @param errcode the error code (not operating system errno!)
875
876 @retval true an error occurred, value not set (OOM?)
877 @retval false value was set without incident, or did not need to be set
878 */
880 if (ll == nullptr) return true;
881
885 }
886 return false; // already set, that's OK then
887 }
888
889 /**
890 Set the error message.
891
892 @param fmt format string. % substitution will be performed.
893 @param ap va_list of the arguments for % substitution.
894 */
895 void set_message(const char *fmt, va_list ap)
896 MY_ATTRIBUTE((format(printf, 2, 0)));
897
898 /**
899 Set the error message (by MySQL error code).
900 The actual message will be looked up using this errcode.
901 As the message is a printf-style format string, % substitution
902 will be performed.
903
904 @param errcode MySQL error code to fetch the message string for
905 @param ap va_list of the arguments for % substitution.
906 */
907 void set_message_by_errcode(longlong errcode, va_list ap);
908
909 public:
910 /**
911 Destructor automatically sends the event on.
912 It is auto-free()d after processing.
913 */
915 if (ll != nullptr) {
916 log_line_submit(this->ll);
918 log_free(msg);
919 }
920 }
921
922 /**
923 "Full customization" constructor. Use one of the LogErr() macro
924 where possible; it's there to help you remember the minimum set
925 of particles and their data-types. Be prepared for stern looks
926 from your reviewers if you use this constructor except for external
927 (loadable) services that have no error messages registered with the
928 server, and therefore need to submit them free-form.
929 */
931 if ((ll = log_line_init()) != nullptr) {
932 if ((msg = (char *)log_malloc(LOG_BUFF_MAX)) == nullptr) {
934 ll = nullptr;
935 }
936 } else
937 msg = nullptr;
938 msg_tag = nullptr;
939 }
940
941 /**
942
943 Set log type.
944
945 @param val the log type (LOG_TYPE_ERROR)
946
947 @retval the LogEvent, for easy fluent-style chaining.
948 */
951 return *this;
952 }
953
954 /**
955 Append a numeric error code
956
957 @param val the MySQL error code (not operating system errno!).
958
959 @retval the LogEvent, for easy fluent-style chaining.
960 */
963 return *this;
964 }
965
966 /**
967 Append a (string) error symbol
968
969 @param val error symbol. NTBS.
970
971 @retval the LogEvent, for easy fluent-style chaining.
972 */
973 LogEvent &errsymbol(const char *val) {
975 return *this;
976 }
977
978 /**
979 Append a (string) SQL state
980
981 @param val the SQLstate. NTBS.
982
983 @retval the LogEvent, for easy fluent-style chaining.
984 */
985 LogEvent &sqlstate(const char *val) {
987 return *this;
988 }
989
990 /**
991 Append a numeric (operating system, as opposed to MySQL) error number.
992
993 @param val the operating system errno.
994
995 @retval the LogEvent, for easy fluent-style chaining.
996 */
999 return *this;
1000 }
1001
1002 /**
1003 Append a textual (operating system, as opposed to MySQL) error message,
1004 vulgo, strerror()
1005
1006 @param val the error message returned by the operating system. NTBS.
1007
1008 @retval the LogEvent, for easy fluent-style chaining.
1009 */
1010 LogEvent &os_errmsg(const char *val) {
1012 return *this;
1013 }
1014
1015 /**
1016 Which source file was the problem detected in?
1017
1018 @param val the source file's name. NTBS.
1019
1020 @retval the LogEvent, for easy fluent-style chaining.
1021 */
1022 LogEvent &source_file(const char *val) {
1024 return *this;
1025 }
1026
1027 /**
1028 Which line in the source file was the problem detected on?
1029
1030 @param val the line number.
1031
1032 @retval the LogEvent, for easy fluent-style chaining.
1033 */
1036 return *this;
1037 }
1038
1039 /**
1040 Which function in the source was the problem detected in?
1041
1042 @param val the function's name. NTBS.
1043
1044 @retval the LogEvent, for easy fluent-style chaining.
1045 */
1046 LogEvent &function(const char *val) {
1048 return *this;
1049 }
1050
1051 /**
1052 Which subsystem in the source was the problem detected in?
1053 ("Repl"/"InnoDB"/"Server")
1054
1055 @param val the subsystem. NTBS.
1056
1057 @retval the LogEvent, for easy fluent-style chaining.
1058 */
1059 LogEvent &subsys(const char *val) {
1060 if (val != nullptr)
1062 return *this;
1063 }
1064
1065 /**
1066 Which component in the source was the problem detected in?
1067 This should be the same string that is given to the
1068 component/service framework.
1069
1070 @param val the component. NTBS.
1071
1072 @retval the LogEvent, for easy fluent-style chaining.
1073 */
1074 LogEvent &component(const char *val) {
1075 if (val != nullptr)
1077 return *this;
1078 }
1079
1080 /**
1081 What user were we working for at the time of the issue?
1082
1083 @param val the user part (of "user@host"). LEX_CSTRING.
1084
1085 @retval the LogEvent, for easy fluent-style chaining.
1086 */
1089 val.length);
1090 return *this;
1091 }
1092
1093 /**
1094 What user were we working for at the time of the issue?
1095
1096 @param val the user part (of "user@host"). NTBS.
1097
1098 @retval the LogEvent, for easy fluent-style chaining.
1099 */
1100 LogEvent &user(const char *val) {
1102 return *this;
1103 }
1104
1105 /**
1106 Whose session did the issue appear in?
1107
1108 @param val the host part (of "user@host"). LEX_CSTRING.
1109
1110 @retval the LogEvent, for easy fluent-style chaining.
1111 */
1114 val.length);
1115 return *this;
1116 }
1117
1118 /**
1119 Whose session did the issue appear in?
1120
1121 @param val the host part (of "user@host"). NTBS.
1122
1123 @retval the LogEvent, for easy fluent-style chaining.
1124 */
1125 LogEvent &host(const char *val) {
1127 return *this;
1128 }
1129
1130 /**
1131 What thread / "connection ID" was the issue detected in?
1132
1133 @param val the thread_ID of the session the issue appeared in
1134
1135 @retval the LogEvent, for easy fluent-style chaining.
1136 */
1139 return *this;
1140 }
1141
1142 /**
1143 What query apparently caused the issue?
1144
1145 @param val the query_ID of the offending query
1146
1147 @retval the LogEvent, for easy fluent-style chaining.
1148 */
1151 return *this;
1152 }
1153
1154 /**
1155 What table were we working on?
1156
1157 @param val the table's name/alias. NTBS.
1158
1159 @retval the LogEvent, for easy fluent-style chaining.
1160 */
1161 LogEvent &table_name(const char *val) {
1163 return *this;
1164 }
1165
1166 /**
1167 Set error message priority.
1168 Assign one of ERROR_LEVEL, WARNING_LEVEL, INFORMATION_LEVEL.
1169 log-writers and other sinks should use this value (rather
1170 than that of LOG_ITEM_LOG_EPRIO):
1171
1172 - file writers should use the value to determine
1173 what label to write (perhaps by submitting it to label_from_prio())
1174
1175 - sinks that submit the event data to a sub-system outside of
1176 the MySQL server (such as syslog, EventLog, systemd journal, etc.)
1177 should translate this value into a priority/log level understood
1178 by that target subsystem.
1179
1180 @param val The priority for this LogEvent.
1181
1182 @retval the LogEvent, for easy fluent-style chaining.
1183 */
1186 return *this;
1187 }
1188
1189 /**
1190 Set a label (usually "warning"/"error"/"information").
1191 Will be derived from prio if not set explicitly.
1192 Some log services may ignore custom labels.
1193
1194 @param val the (custom) label to set
1195
1196 @retval the LogEvent, for easy fluent-style chaining.
1197 */
1198 LogEvent &label(const char *val) {
1200 return *this;
1201 }
1202
1203 /**
1204 Add a message to the event, verbatim (i.e. with no % substitutions).
1205 This is an analog of message("%s", message); it can be used when
1206 message may contain user input or a message from another subsystem
1207 that could contain % that must not be interpreted as an invitation
1208 to do % substitutions.
1209
1210 If you use this in a context other than an external service that
1211 has no messages registered with the server, your reviewers will
1212 say unkind things about you. Use registered messages and their
1213 error codes wherever possible!
1214
1215 @param msg_arg the message. % substitution will not happen.
1216
1217 @retval the LogEvent, for easy fluent-style chaining.
1218 */
1219 LogEvent &verbatim(const char *msg_arg) {
1221 return *this;
1222 }
1223
1224 /**
1225 Fill in a format string by substituting the % with the given
1226 arguments, then add the result as the event's message.
1227 This should be used very sparingly; use registered messages
1228 and their error codes wherever possible!
1229
1230 @param fmt message (treated as a printf-style format-string,
1231 so % substitution will happen)
1232 @param ap valist to satisfy any % in the message
1233
1234 @retval the LogEvent, for easy fluent-style chaining.
1235 */
1236 LogEvent &messagev(const char *fmt, va_list ap)
1237 MY_ATTRIBUTE((format(printf, 2, 0))) {
1238 set_message(fmt, ap);
1239 return *this;
1240 }
1241
1242 /**
1243 Fill in a format string by substituting the % with the given
1244 arguments, then add the result as the event's message.
1245
1246 If you use this in a context other than an external service that
1247 has no messages registered with the server, your reviewers will
1248 say unkind things about you. Use registered messages and their
1249 error codes wherever possible!
1250
1251 @param fmt message (treated as a printf-style format-string,
1252 so % substitution will happen)
1253 @param ... varargs to satisfy any % in the message
1254
1255 @retval the LogEvent, for easy fluent-style chaining.
1256 */
1257 LogEvent &message(const char *fmt, ...) MY_ATTRIBUTE((format(printf, 2, 3)));
1258
1259 /**
1260 Fill in a format string by substituting the % with the given
1261 arguments and tag, then add the result as the event's message.
1262
1263 @param tag Tag to prefix to message.
1264 @param fmt message (treated as a printf-style format-string,
1265 so % substitution will happen)
1266 @param ... varargs to satisfy any % in the message
1267
1268 @retval the LogEvent, for easy fluent-style chaining.
1269 */
1270 LogEvent &message_quoted(const char *tag, const char *fmt, ...)
1271 MY_ATTRIBUTE((format(printf, 3, 4))) {
1272 msg_tag = tag;
1273
1274 va_list args;
1275 va_start(args, fmt);
1276 set_message(fmt, args);
1277 va_end(args);
1278
1279 return *this;
1280 }
1281
1282 /**
1283 Find an error message by its MySQL error code.
1284 Substitute the % in that message with the given
1285 arguments, then add the result as the event's message.
1286
1287 @param errcode MySQL error code for the message in question,
1288 e.g. ER_STARTUP
1289 @param ... varargs to satisfy any % in the message
1290
1291 @retval the LogEvent, for easy fluent-style chaining.
1292 */
1294 va_list args;
1295 va_start(args, errcode);
1297 va_end(args);
1298
1299 return *this;
1300 }
1301
1302 /**
1303 Find an error message by its MySQL error code. Substitute the % in that
1304 message with the given arguments list, then add the result as the event's
1305 message.
1306
1307 @param errcode MySQL error code for the message in question,
1308 e.g. ER_STARTUP
1309 @param args varargs to satisfy any % in the message
1310
1311 @retval the LogEvent, for easy fluent-style chaining.
1312 */
1315
1316 return *this;
1317 }
1318
1319 LogEvent &lookup_quoted(longlong errcode, const char *tag, ...) {
1320 msg_tag = tag;
1321
1322 va_list args;
1323 va_start(args, tag);
1325 va_end(args);
1326
1327 return *this;
1328 }
1329
1330 LogEvent &lookup_quotedv(longlong errcode, const char *tag, va_list vl) {
1331 msg_tag = tag;
1333
1334 return *this;
1335 }
1336
1337 /**
1338 Add a ad hoc integer value with the given key.
1339
1340 @param key user-defined key (i.e. not wellknown). NTBS.
1341 @param val value.
1342
1343 @retval the LogEvent, for easy fluent-style chaining.
1344 */
1345 LogEvent &int_value(const char *key, longlong val) {
1348 val);
1349 return *this;
1350 }
1351
1352 /**
1353 Add a ad hoc (not "well-known") float value with the given key.
1354
1355 @param key user-defined key (i.e. not wellknown). NTBS.
1356 @param val value.
1357
1358 @retval the LogEvent, for easy fluent-style chaining.
1359 */
1360 LogEvent &float_value(const char *key, double val) {
1363 val);
1364 return *this;
1365 }
1366
1367 /**
1368 Add a ad hoc string value with the given key.
1369
1370 @param key user-defined key (i.e. not wellknown). NTBS.
1371 @param val value.
1372 @param len length in bytes of the value.
1373
1374 @retval the LogEvent, for easy fluent-style chaining.
1375 */
1376 LogEvent &string_value(const char *key, const char *val, size_t len) {
1380 val, len);
1381 return *this;
1382 }
1383
1384 /**
1385 Add a ad hoc string value with the given key.
1386
1387 @param key user-defined key (i.e. not wellknown). NTBS.
1388 @param val value. NTBS.
1389
1390 @retval the LogEvent, for easy fluent-style chaining.
1391 */
1392 LogEvent &string_value(const char *key, const char *val) {
1396 val);
1397 return *this;
1398 }
1399};
1400
1401inline void LogEvent::set_message_by_errcode(longlong errcode, va_list ap) {
1402 const char *fmt = error_msg_by_errcode((int)errcode);
1403
1404 if ((fmt == nullptr) || (*fmt == '\0')) fmt = "invalid error code";
1405
1407 set_message(fmt, ap);
1408}
1409
1410inline void LogEvent::set_message(const char *fmt, va_list ap) {
1411 if ((ll != nullptr) && (msg != nullptr)) {
1412 char buf[LOG_BUFF_MAX];
1413 if (msg_tag != nullptr) {
1414 snprintf(buf, LOG_BUFF_MAX, "%s: \'%s\'", msg_tag, fmt);
1415 fmt = buf;
1416 }
1417 size_t len = log_msg(msg, LOG_BUFF_MAX, fmt, ap);
1418 if (len >= LOG_BUFF_MAX) {
1419 const char ellipsis[] = " <...>";
1420 len = LOG_BUFF_MAX - 1;
1421 strcpy(&msg[LOG_BUFF_MAX - sizeof(ellipsis)], ellipsis);
1422 }
1424 len);
1425 }
1426}
1427
1428inline LogEvent &LogEvent::message(const char *fmt, ...) {
1429 va_list args;
1430 va_start(args, fmt);
1431 set_message(fmt, args);
1432 va_end(args);
1433
1434 return *this;
1435}
1436
1437// Methods initialize and de-initialize logging service for plugins.
1438#if defined(MYSQL_DYNAMIC_PLUGIN)
1439
1440/**
1441 Method to de-initialize logging service in plugin.
1442
1443 param[in,out] reg_srv Plugin registry service.
1444 param[in,out] log_bi Error logging service.
1445 param[in,out] log_bs String service for error logging.
1446*/
1447inline void deinit_logging_service_for_plugin(
1448 SERVICE_TYPE(registry) * *reg_srv, SERVICE_TYPE(log_builtins) * *log_bi,
1449 SERVICE_TYPE(log_builtins_string) * *log_bs) {
1450 using log_builtins_t = SERVICE_TYPE_NO_CONST(log_builtins);
1451 using log_builtins_string_t = SERVICE_TYPE_NO_CONST(log_builtins_string);
1452 if (*log_bi)
1453 (*reg_srv)->release(
1454 reinterpret_cast<my_h_service>(const_cast<log_builtins_t *>(*log_bi)));
1455 if (*log_bs)
1456 (*reg_srv)->release(reinterpret_cast<my_h_service>(
1457 const_cast<log_builtins_string_t *>(*log_bs)));
1459 *log_bi = nullptr;
1460 *log_bs = nullptr;
1461 *reg_srv = nullptr;
1462}
1463
1464/**
1465 Method to de-initialize logging service in plugin.
1466
1467 param[in,out] reg_srv Plugin registry service.
1468 param[in,out] log_bi Error logging service.
1469 param[in,out] log_bs String service for error logging.
1470
1471 @retval false Success.
1472 @retval true Failed.
1473*/
1474inline bool init_logging_service_for_plugin(
1475 SERVICE_TYPE(registry) * *reg_srv, SERVICE_TYPE(log_builtins) * *log_bi,
1476 SERVICE_TYPE(log_builtins_string) * *log_bs) {
1477 my_h_service log_srv = nullptr;
1478 my_h_service log_str_srv = nullptr;
1480 if (!(*reg_srv)->acquire("log_builtins.mysql_server", &log_srv) &&
1481 !(*reg_srv)->acquire("log_builtins_string.mysql_server", &log_str_srv)) {
1482 (*log_bi) = reinterpret_cast<SERVICE_TYPE(log_builtins) *>(log_srv);
1483 (*log_bs) =
1484 reinterpret_cast<SERVICE_TYPE(log_builtins_string) *>(log_str_srv);
1485 } else {
1486 deinit_logging_service_for_plugin(reg_srv, log_bi, log_bs);
1487 return true;
1488 }
1489 return false;
1490}
1491
1492#elif defined(EXTRA_CODE_FOR_UNIT_TESTING)
1493
1494/**
1495 Method is used by unit tests.
1496
1497 param[in,out] reg_srv Plugin registry service.
1498 param[in,out] log_bi Error logging service.
1499 param[in,out] log_bs String service for error logging.
1500
1501 @retval false Success.
1502 @retval true Failed.
1503*/
1504inline bool init_logging_service_for_plugin(
1505 SERVICE_TYPE(registry) * *reg_srv [[maybe_unused]],
1506 SERVICE_TYPE(log_builtins) * *log_bi [[maybe_unused]],
1507 SERVICE_TYPE(log_builtins_string) * *log_bs [[maybe_unused]])
1508
1509{
1510 return false;
1511}
1512
1513/**
1514 Method is used by unit tests.
1515
1516 param[in,out] reg_srv Plugin registry service.
1517 param[in,out] log_bi Error logging service.
1518 param[in,out] log_bs String service for error logging.
1519*/
1520inline void deinit_logging_service_for_plugin(
1521 SERVICE_TYPE(registry) * *reg_srv [[maybe_unused]],
1522 SERVICE_TYPE(log_builtins) * *log_bi [[maybe_unused]],
1523 SERVICE_TYPE(log_builtins_string) * *log_bs [[maybe_unused]]) {}
1524
1525#endif // MYSQL_DYNAMIC_PLUGIN
1526
1527#endif // __cplusplus
1528
1529#endif
Modular logger: fluid API.
Definition: log_builtins.h:865
~LogEvent()
Destructor automatically sends the event on.
Definition: log_builtins.h:914
LogEvent & host(const char *val)
Whose session did the issue appear in?
Definition: log_builtins.h:1125
LogEvent & user(const char *val)
What user were we working for at the time of the issue?
Definition: log_builtins.h:1100
LogEvent & string_value(const char *key, const char *val, size_t len)
Add a ad hoc string value with the given key.
Definition: log_builtins.h:1376
LogEvent()
"Full customization" constructor.
Definition: log_builtins.h:930
char * msg
Definition: log_builtins.h:868
LogEvent & lookup_quoted(longlong errcode, const char *tag,...)
Definition: log_builtins.h:1319
LogEvent & lookup_quotedv(longlong errcode, const char *tag, va_list vl)
Definition: log_builtins.h:1330
LogEvent & prio(longlong val)
Set error message priority.
Definition: log_builtins.h:1184
LogEvent & subsys(const char *val)
Which subsystem in the source was the problem detected in? ("Repl"/"InnoDB"/"Server")
Definition: log_builtins.h:1059
LogEvent & errcode(longlong val)
Append a numeric error code.
Definition: log_builtins.h:961
LogEvent & source_file(const char *val)
Which source file was the problem detected in?
Definition: log_builtins.h:1022
bool set_errcode(longlong errcode)
Set MySQL error-code if none has been set yet.
Definition: log_builtins.h:879
LogEvent & os_errno(longlong val)
Append a numeric (operating system, as opposed to MySQL) error number.
Definition: log_builtins.h:997
LogEvent & type(enum_log_type val)
Set log type.
Definition: log_builtins.h:949
LogEvent & thread_id(longlong val)
What thread / "connection ID" was the issue detected in?
Definition: log_builtins.h:1137
LogEvent & os_errmsg(const char *val)
Append a textual (operating system, as opposed to MySQL) error message, vulgo, strerror()
Definition: log_builtins.h:1010
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:1074
LogEvent & lookupv(longlong errcode, va_list args)
Find an error message by its MySQL error code.
Definition: log_builtins.h:1313
const char * msg_tag
Definition: log_builtins.h:869
LogEvent & verbatim(const char *msg_arg)
Add a message to the event, verbatim (i.e.
Definition: log_builtins.h:1219
LogEvent & message(const char *fmt,...)
Fill in a format string by substituting the % with the given arguments, then add the result as the ev...
Definition: log_builtins.h:1428
LogEvent & errsymbol(const char *val)
Append a (string) error symbol.
Definition: log_builtins.h:973
LogEvent & table_name(const char *val)
What table were we working on?
Definition: log_builtins.h:1161
LogEvent & label(const char *val)
Set a label (usually "warning"/"error"/"information").
Definition: log_builtins.h:1198
LogEvent & source_line(longlong val)
Which line in the source file was the problem detected on?
Definition: log_builtins.h:1034
LogEvent & query_id(longlong val)
What query apparently caused the issue?
Definition: log_builtins.h:1149
LogEvent & message_quoted(const char *tag, const char *fmt,...)
Fill in a format string by substituting the % with the given arguments and tag, then add the result a...
Definition: log_builtins.h:1270
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:1236
LogEvent & sqlstate(const char *val)
Append a (string) SQL state.
Definition: log_builtins.h:985
LogEvent & float_value(const char *key, double val)
Add a ad hoc (not "well-known") float value with the given key.
Definition: log_builtins.h:1360
log_line * ll
Definition: log_builtins.h:867
LogEvent & int_value(const char *key, longlong val)
Add a ad hoc integer value with the given key.
Definition: log_builtins.h:1345
LogEvent & user(LEX_CSTRING val)
What user were we working for at the time of the issue?
Definition: log_builtins.h:1087
LogEvent & string_value(const char *key, const char *val)
Add a ad hoc string value with the given key.
Definition: log_builtins.h:1392
void set_message_by_errcode(longlong errcode, va_list ap)
Set the error message (by MySQL error code).
Definition: log_builtins.h:1401
void set_message(const char *fmt, va_list ap)
Set the error message.
Definition: log_builtins.h:1410
LogEvent & lookup(longlong errcode,...)
Find an error message by its MySQL error code.
Definition: log_builtins.h:1293
LogEvent & host(LEX_CSTRING val)
Whose session did the issue appear in?
Definition: log_builtins.h:1112
Specifies macros to define Components.
void write(W *w, const T &t, const char *key, size_t key_sz)
Definition: sdi_impl.h:334
struct my_h_service_imp * my_h_service
A handle type for acquired Service.
Definition: registry.h:32
#define malloc(A)
Definition: lexyy.cc:914
#define free(A)
Definition: lexyy.cc:915
Error logging, slow query logging, general query logging: If it's server-internal,...
#define log_line_init
Definition: log_builtins.h:717
#define log_line_item_types_seen
Definition: log_builtins.h:721
const mysql_service_log_builtins_string_t * log_bs
string built-ins
Definition: keyring_file.cc:136
#define log_set_cstring
Definition: log_builtins.h:726
#define log_set_float
Definition: log_builtins.h:724
#define log_malloc
Definition: log_builtins.h:727
#define log_line_exit
Definition: log_builtins.h:718
#define log_line_submit
Definition: log_builtins.h:722
#define log_line_item_set
Definition: log_builtins.h:720
#define log_set_int
Definition: log_builtins.h:723
#define log_msg
Definition: log_builtins.h:729
#define error_msg_by_errcode
Definition: log_builtins.h:730
#define log_free
Definition: log_builtins.h:728
#define log_line_item_set_with_key
Definition: log_builtins.h:719
const mysql_service_log_builtins_t * log_bi
accessor built-ins
Definition: keyring_file.cc:135
#define log_set_lexstring
Definition: log_builtins.h:725
enum enum_log_service_error log_service_error
Error codes.
#define LOG_BUFF_MAX
advisory.
Definition: log_shared.h:224
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_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_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_SYS_ERRNO
OS errno.
Definition: log_shared.h:129
@ 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_MSC_HOST
responsible user on host ...
Definition: log_shared.h:137
@ LOG_ITEM_SYS_STRERROR
OS strerror()
Definition: log_shared.h:130
@ LOG_ITEM_SQL_STATE
SQL state.
Definition: log_shared.h:128
@ LOG_ITEM_FREE_NONE
Definition: log_shared.h:178
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
void log_sink_buffer_check_timeout(void)
Convenience function.
Definition: log_sink_buffer.cc:370
static int log_type
Definition: mi_log.cc:46
Header for compiler-dependent features.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
long long int longlong
Definition: my_inttypes.h:54
uint32_t uint32
Definition: my_inttypes.h:66
loglevel
Definition: my_loglevel.h:40
Definition: buf0block_hint.cc:29
constexpr value_type timestamp
Definition: classic_protocol_constants.h:273
Definition: os0file.h:85
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
stdx::expected< void, std::error_code > close(file_handle_type native_handle)
close file handle.
Definition: file.h:238
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:391
stdx::expected< int, std::error_code > open(const char *fname, int flags, mode_t mode) noexcept
Definition: file_handle.cc:81
required string key
Definition: replication_asynchronous_connection_failover.proto:59
static int compare(size_t a, size_t b)
Function to compare two size_t integers for their relative order.
Definition: rpl_utility.cc:104
#define DECLARE_METHOD(retval, name, args)
Declares a method as a part of the Service definition.
Definition: service.h:102
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:75
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:90
#define SERVICE_TYPE_NO_CONST(name)
Generates the standard Service type name.
Definition: service.h:70
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:85
Specifies macros to define Service Implementations.
Declaration of the registry plugin service.
const mysql_service_registry_t * mysql_plugin_registry_acquire()
Returns a new reference to the "registry" service.
Definition: plugin_registry_service.cc:46
int mysql_plugin_registry_release(const mysql_service_registry_t *)
Releases a registry service reference.
Definition: plugin_registry_service.cc:74
case opt name
Definition: sslopt-case.h:32
Definition: mysql_lex_string.h:39
const char * str
Definition: mysql_lex_string.h:40
size_t length
Definition: mysql_lex_string.h:41
Iterator over the key/value pairs of a log_line.
Definition: keyring_log_builtins_definition.cc:63
Definition: log_shared.h:195
log_line ("log event")
Definition: keyring_log_builtins_definition.cc:71
static const mysql_service_registry_t * reg_srv
Initialize parameters required for error logging.
Definition: test_plugin.cc:61
unsigned int uint
Definition: uca-dump.cc:29
Definition: log_shared.h:184
int n
Definition: xcom_base.cc:505