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