MySQL  8.0.17
Source Code Documentation
log_builtins.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
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 
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 no 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 no 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 no 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 no 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 */
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,
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,
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(size_t, notify_client,
632  (void *thd, uint severity, uint code, char *to, size_t n,
633  const char *format, ...))
634 MY_ATTRIBUTE((format(printf, 6, 7)));
635 END_SERVICE_DEFINITION(log_builtins_tmp)
636 
637 /**
638  Syslog/Eventlog functions for logging services.
639 */
640 BEGIN_SERVICE_DEFINITION(log_builtins_syseventlog)
641 DECLARE_METHOD(int, open, (const char *name, int option, int facility));
642 DECLARE_METHOD(int, write, (enum loglevel level, const char *msg));
643 DECLARE_METHOD(int, close, (void));
644 END_SERVICE_DEFINITION(log_builtins_syseventlog)
645 
646 #ifdef __cplusplus
647 
648 #if !defined(LOG_H)
649 
650 extern SERVICE_TYPE(log_builtins) * log_bi;
651 extern SERVICE_TYPE(log_builtins_string) * log_bs;
652 
653 #define log_line_init log_bi->line_init
654 #define log_line_exit log_bi->line_exit
655 #define log_line_item_set_with_key log_bi->line_item_set_with_key
656 #define log_line_item_set log_bi->line_item_set
657 #define log_line_item_types_seen log_bi->line_item_types_seen
658 #define log_line_submit log_bi->line_submit
659 #define log_set_int log_bi->item_set_int
660 #define log_set_float log_bi->item_set_float
661 #define log_set_lexstring log_bi->item_set_lexstring
662 #define log_set_cstring log_bi->item_set_cstring
663 #define log_malloc log_bs->malloc
664 #define log_free log_bs->free
665 #define log_msg log_bs->substitutev
666 #define error_msg_by_errcode log_bi->errmsg_by_errcode
667 #define error_code_by_errsymbol log_bi->errcode_by_errsymbol
668 #else
669 
670 #include "sql/derror.h"
671 
672 #define log_malloc(s) my_malloc(0, (s), MYF(0))
673 #define log_free my_free
674 #define log_msg vsnprintf
675 #define error_msg_by_errcode error_message_for_error_log
676 #define error_code_by_errsymbol mysql_symbol_to_errno
677 #define log_set_int log_item_set_int
678 #define log_set_float log_item_set_float
679 #define log_set_lexstring log_item_set_lexstring
680 #define log_set_cstring log_item_set_cstring
681 
682 /**
683  Very long-running functions during server start-up can use this
684  function to check whether the time-out for buffered logging has
685  been reached. If so and we have urgent information, all buffered
686  log events will be flushed to the log using built-in default-logger
687  for the time being. The information will be kept until start-up
688  completes in case it later turns out the user configured a loadable
689  logger, in which case we'll also flush the buffered information to
690  that logger later once the logger becomes available.
691 
692  This function should only be used during start-up; once external
693  components are loaded by the component framework, this function
694  should no longer be called (as log events are no longer buffered,
695  but logged immediately).
696 */
698 #endif // LOG_H
699 
700 #ifndef DISABLE_ERROR_LOGGING
701 
702 #if defined(LOG_COMPONENT_TAG)
703 
704 #define LogErr(severity, ecode, ...) \
705  LogEvent() \
706  .prio(severity) \
707  .errcode(ecode) \
708  .subsys(LOG_SUBSYSTEM_TAG) \
709  .component(LOG_COMPONENT_TAG) \
710  .source_line(__LINE__) \
711  .source_file(MY_BASENAME) \
712  .function(__FUNCTION__) \
713  .lookup(ecode, ##__VA_ARGS__)
714 
715 #define LogPluginErr(severity, ecode, ...) \
716  LogEvent() \
717  .prio(severity) \
718  .errcode(ecode) \
719  .subsys(LOG_SUBSYSTEM_TAG) \
720  .component("plugin:" LOG_COMPONENT_TAG) \
721  .source_line(__LINE__) \
722  .source_file(MY_BASENAME) \
723  .function(__FUNCTION__) \
724  .lookup_quoted(ecode, "Plugin " LOG_COMPONENT_TAG " reported", \
725  ##__VA_ARGS__)
726 
727 #define LogPluginErrV(severity, ecode, vl) \
728  LogEvent() \
729  .prio(severity) \
730  .errcode(ecode) \
731  .subsys(LOG_SUBSYSTEM_TAG) \
732  .component("plugin:" LOG_COMPONENT_TAG) \
733  .source_line(__LINE__) \
734  .source_file(MY_BASENAME) \
735  .function(__FUNCTION__) \
736  .lookup_quotedv(ecode, "Plugin " LOG_COMPONENT_TAG " reported", vl)
737 
738 #define LogPluginErrMsg(severity, ecode, ...) \
739  LogEvent() \
740  .prio(severity) \
741  .errcode(ecode) \
742  .subsys(LOG_SUBSYSTEM_TAG) \
743  .component("plugin:" LOG_COMPONENT_TAG) \
744  .source_line(__LINE__) \
745  .source_file(MY_BASENAME) \
746  .function(__FUNCTION__) \
747  .message_quoted("Plugin " LOG_COMPONENT_TAG " reported", ##__VA_ARGS__)
748 
749 #else
750 
751 #define LogErr(severity, ecode, ...) \
752  LogEvent() \
753  .prio(severity) \
754  .errcode(ecode) \
755  .subsys(LOG_SUBSYSTEM_TAG) \
756  .source_line(__LINE__) \
757  .source_file(MY_BASENAME) \
758  .function(__FUNCTION__) \
759  .lookup(ecode, ##__VA_ARGS__)
760 
761 #endif
762 
763 #else
764 
765 inline void dummy_log_message(longlong severity MY_ATTRIBUTE((unused)),
766  longlong ecode MY_ATTRIBUTE((unused)), ...) {
767  return;
768 }
769 
770 #define LogErr(severity, ecode, ...) \
771  dummy_log_message(severity, ecode, ##__VA_ARGS__)
772 
773 #define LogPluginErr(severity, ecode, ...) \
774  dummy_log_message(severity, ecode, ##__VA_ARGS__)
775 #define LogPluginErrV(severity, ecode, ...) \
776  dummy_log_message(severity, ecode, ##__VA_ARGS__)
777 #define LogPluginErrMsg(severity, ecode, ...) \
778  dummy_log_message(severity, ecode, ##__VA_ARGS__)
779 
780 #endif // DISABLE_ERROR_LOGGING
781 
782 /**
783  Modular logger: fluid API. Server-internal. Lets you use safe and
784  expressive syntax, like so:
785 
786  LogEvent(LOG_TYPE_ERROR).prio(INFORMATION_LEVEL).message("Meow! %d", 4711);
787 */
788 
789 class LogEvent {
790  private:
792  char *msg;
793  const char *msg_tag;
794 
795  /**
796  Set MySQL error-code if none has been set yet.
797 
798  @param errcode the error code (not operating system errno!)
799 
800  @retval true an error occurred, value not set (OOM?)
801  @retval false value was set without incident, or did not need to be set
802  */
804  if (ll == nullptr) return true;
805 
809  }
810  return false; // already set, that's OK then
811  }
812 
813  /**
814  Set the error message.
815 
816  @param fmt format string. % substitution will be performed.
817  @param ap va_list of the arguments for % substitution.
818  */
819  void set_message(const char *fmt, va_list ap)
820  MY_ATTRIBUTE((format(printf, 2, 0)));
821 
822  /**
823  Set the error message (by MySQL error code).
824  The actual message will be looked up using this errcode.
825  As the message is a printf-style format string, % substitution
826  will be performed.
827 
828  @param errcode MySQL error code to fetch the message string for
829  @param ap va_list of the arguments for % substitution.
830  */
831  void set_message_by_errcode(longlong errcode, va_list ap);
832 
833  public:
834  /**
835  Destructor automatically sends the event on.
836  It is auto-free()d after processing.
837  */
839  if (ll != nullptr) {
840  log_line_submit(this->ll);
841  log_line_exit(ll);
842  log_free(msg);
843  }
844  }
845 
846  /**
847  "Full customization" constructor. Use one of the LogErr() macro
848  where possible; it's there to help you remember the minimum set
849  of particles and their data-types. Be prepared for stern looks
850  from your reviewers if you use this constructor except for external
851  (loadable) services that have no error messages registered with the
852  server, and therefore need to submit them free-form.
853  */
855  if ((ll = log_line_init()) != nullptr) {
856  if ((msg = (char *)log_malloc(LOG_BUFF_MAX)) == nullptr) {
857  log_line_exit(ll);
858  ll = nullptr;
859  }
860  } else
861  msg = nullptr;
862  msg_tag = nullptr;
863  }
864 
865  /**
866 
867  Set log type.
868 
869  @param val the log type (LOG_TYPE_ERROR)
870 
871  @retval the LogEvent, for easy fluent-style chaining.
872  */
875  return *this;
876  }
877 
878  /**
879  Append a numeric error code
880 
881  @param val the MySQL error code (not operating system errno!).
882 
883  @retval the LogEvent, for easy fluent-style chaining.
884  */
887  return *this;
888  }
889 
890  /**
891  Append a (string) error symbol
892 
893  @param val error symbol. NTBS.
894 
895  @retval the LogEvent, for easy fluent-style chaining.
896  */
897  LogEvent &errsymbol(const char *val) {
899  return *this;
900  }
901 
902  /**
903  Append a (string) SQL state
904 
905  @param val the SQLstate. NTBS.
906 
907  @retval the LogEvent, for easy fluent-style chaining.
908  */
909  LogEvent &sqlstate(const char *val) {
911  return *this;
912  }
913 
914  /**
915  Append a numeric (operating system, as opposed to MySQL) error number.
916 
917  @param val the operating system errno.
918 
919  @retval the LogEvent, for easy fluent-style chaining.
920  */
923  return *this;
924  }
925 
926  /**
927  Append a textual (operating system, as opposed to MySQL) error message,
928  vulgo, strerror()
929 
930  @param val the error message returned by the operating system. NTBS.
931 
932  @retval the LogEvent, for easy fluent-style chaining.
933  */
934  LogEvent &os_errmsg(const char *val) {
936  return *this;
937  }
938 
939  /**
940  Which source file was the problem detected in?
941 
942  @param val the source file's name. NTBS.
943 
944  @retval the LogEvent, for easy fluent-style chaining.
945  */
946  LogEvent &source_file(const char *val) {
948  return *this;
949  }
950 
951  /**
952  Which line in the source file was the problem detected on?
953 
954  @param val the line number.
955 
956  @retval the LogEvent, for easy fluent-style chaining.
957  */
960  return *this;
961  }
962 
963  /**
964  Which function in the source was the problem detected in?
965 
966  @param val the function's name. NTBS.
967 
968  @retval the LogEvent, for easy fluent-style chaining.
969  */
970  LogEvent &function(const char *val) {
972  return *this;
973  }
974 
975  /**
976  Which subsystem in the source was the problem detected in?
977  ("Repl"/"InnoDB"/"Server")
978 
979  @param val the subsystem. NTBS.
980 
981  @retval the LogEvent, for easy fluent-style chaining.
982  */
983  LogEvent &subsys(const char *val) {
984  if (val != nullptr)
986  return *this;
987  }
988 
989  /**
990  Which component in the source was the problem detected in?
991  This should be the same string that is given to the
992  component/service framework.
993 
994  @param val the component. NTBS.
995 
996  @retval the LogEvent, for easy fluent-style chaining.
997  */
998  LogEvent &component(const char *val) {
999  if (val != nullptr)
1001  return *this;
1002  }
1003 
1004  /**
1005  What user were we working for at the time of the issue?
1006 
1007  @param val the user part (of "user@host"). LEX_CSTRING.
1008 
1009  @retval the LogEvent, for easy fluent-style chaining.
1010  */
1013  val.length);
1014  return *this;
1015  }
1016 
1017  /**
1018  What user were we working for at the time of the issue?
1019 
1020  @param val the user part (of "user@host"). NTBS.
1021 
1022  @retval the LogEvent, for easy fluent-style chaining.
1023  */
1024  LogEvent &user(const char *val) {
1026  return *this;
1027  }
1028 
1029  /**
1030  Whose session did the issue appear in?
1031 
1032  @param val the host part (of "user@host"). LEX_CSTRING.
1033 
1034  @retval the LogEvent, for easy fluent-style chaining.
1035  */
1038  val.length);
1039  return *this;
1040  }
1041 
1042  /**
1043  Whose session did the issue appear in?
1044 
1045  @param val the host part (of "user@host"). NTBS.
1046 
1047  @retval the LogEvent, for easy fluent-style chaining.
1048  */
1049  LogEvent &host(const char *val) {
1051  return *this;
1052  }
1053 
1054  /**
1055  What thread / "connection ID" was the issue detected in?
1056 
1057  @param val the thread_ID of the session the issue appeared in
1058 
1059  @retval the LogEvent, for easy fluent-style chaining.
1060  */
1063  return *this;
1064  }
1065 
1066  /**
1067  What query apparently caused the issue?
1068 
1069  @param val the query_ID of the offending query
1070 
1071  @retval the LogEvent, for easy fluent-style chaining.
1072  */
1075  return *this;
1076  }
1077 
1078  /**
1079  What table were we working on?
1080 
1081  @param val the table's name/alias. NTBS.
1082 
1083  @retval the LogEvent, for easy fluent-style chaining.
1084  */
1085  LogEvent &table_name(const char *val) {
1087  return *this;
1088  }
1089 
1090  /**
1091  Set error message priority.
1092  Assign one of ERROR_LEVEL, WARNING_LEVEL, INFORMATION_LEVEL.
1093  log-writers and other sinks should use this value (rather
1094  than that of LOG_ITEM_LOG_EPRIO):
1095 
1096  - file writers should use the value to determine
1097  what label to write (perhaps by submitting it to label_from_prio())
1098 
1099  - sinks that submit the event data to a sub-system outside of
1100  the MySQL server (such as syslog, EventLog, systemd journal, etc.)
1101  should translate this value into a priority/log level understood
1102  by that target subsystem.
1103 
1104  @param val The priority for this LogEvent.
1105 
1106  @retval the LogEvent, for easy fluent-style chaining.
1107  */
1110  return *this;
1111  }
1112 
1113  /**
1114  Set a label (usually "warning"/"error"/"information").
1115  Will be derived from prio if not set explicitly.
1116  Some log services may ignore custom labels.
1117 
1118  @param val the (custom) label to set
1119 
1120  @retval the LogEvent, for easy fluent-style chaining.
1121  */
1122  LogEvent &label(const char *val) {
1124  return *this;
1125  }
1126 
1127  /**
1128  Add a message to the event, verbatim (i.e. with no % substitutions).
1129  This is an analog of message("%s", message); it can be used when
1130  message may contain user input or a message from another subsystem
1131  that could contain % that must not be interpreted as an invitation
1132  to do % substitutions.
1133 
1134  If you use this in a context other than an external service that
1135  has no messages registered with the server, your reviewers will
1136  say unkind things about you. Use registered messages and their
1137  error codes wherever possible!
1138 
1139  @param msg_arg the message. % substitution will not happen.
1140 
1141  @retval the LogEvent, for easy fluent-style chaining.
1142  */
1143  LogEvent &verbatim(const char *msg_arg) {
1145  return *this;
1146  }
1147 
1148  /**
1149  Fill in a format string by substituting the % with the given
1150  arguments, then add the result as the event's message.
1151  This should be used very sparingly; use registered messages
1152  and their error codes wherever possible!
1153 
1154  @param fmt message (treated as a printf-style format-string,
1155  so % substitution will happen)
1156  @param ap valist to satisfy any % in the message
1157 
1158  @retval the LogEvent, for easy fluent-style chaining.
1159  */
1160  LogEvent &messagev(const char *fmt, va_list ap)
1161  MY_ATTRIBUTE((format(printf, 2, 0))) {
1162  set_message(fmt, ap);
1163  return *this;
1164  }
1165 
1166  /**
1167  Fill in a format string by substituting the % with the given
1168  arguments, then add the result as the event's message.
1169 
1170  If you use this in a context other than an external service that
1171  has no messages registered with the server, your reviewers will
1172  say unkind things about you. Use registered messages and their
1173  error codes wherever possible!
1174 
1175  @param fmt message (treated as a printf-style format-string,
1176  so % substitution will happen)
1177  @param ... varargs to satisfy any % in the message
1178 
1179  @retval the LogEvent, for easy fluent-style chaining.
1180  */
1181  LogEvent &message(const char *fmt, ...) MY_ATTRIBUTE((format(printf, 2, 3)));
1182 
1183  /**
1184  Fill in a format string by substituting the % with the given
1185  arguments and tag, then add the result as the event's message.
1186 
1187  @param tag Tag to prefix to message.
1188  @param fmt message (treated as a printf-style format-string,
1189  so % substitution will happen)
1190  @param ... varargs to satisfy any % in the message
1191 
1192  @retval the LogEvent, for easy fluent-style chaining.
1193  */
1194  LogEvent &message_quoted(const char *tag, const char *fmt, ...)
1195  MY_ATTRIBUTE((format(printf, 3, 4))) {
1196  msg_tag = tag;
1197 
1198  va_list args;
1199  va_start(args, fmt);
1200  set_message(fmt, args);
1201  va_end(args);
1202 
1203  return *this;
1204  }
1205 
1206  /**
1207  Find an error message by its MySQL error code.
1208  Substitute the % in that message with the given
1209  arguments, then add the result as the event's message.
1210 
1211  @param errcode MySQL error code for the message in question,
1212  e.g. ER_STARTUP
1213  @param ... varargs to satisfy any % in the message
1214 
1215  @retval the LogEvent, for easy fluent-style chaining.
1216  */
1218  va_list args;
1219  va_start(args, errcode);
1221  va_end(args);
1222 
1223  return *this;
1224  }
1225 
1226  /**
1227  Find an error message by its MySQL error code. Substitute the % in that
1228  message with the given arguments list, then add the result as the event's
1229  message.
1230 
1231  @param errcode MySQL error code for the message in question,
1232  e.g. ER_STARTUP
1233  @param args varargs to satisfy any % in the message
1234 
1235  @retval the LogEvent, for easy fluent-style chaining.
1236  */
1237  LogEvent &lookupv(longlong errcode, va_list args) {
1239 
1240  return *this;
1241  }
1242 
1243  LogEvent &lookup_quoted(longlong errcode, const char *tag, ...) {
1244  msg_tag = tag;
1245 
1246  va_list args;
1247  va_start(args, tag);
1249  va_end(args);
1250 
1251  return *this;
1252  }
1253 
1254  LogEvent &lookup_quotedv(longlong errcode, const char *tag, va_list vl) {
1255  msg_tag = tag;
1257 
1258  return *this;
1259  }
1260 
1261  /**
1262  Add a ad hoc integer value with the given key.
1263 
1264  @param key user-defined key (i.e. not wellknown). NTBS.
1265  @param val value.
1266 
1267  @retval the LogEvent, for easy fluent-style chaining.
1268  */
1269  LogEvent &int_value(const char *key, longlong val) {
1272  val);
1273  return *this;
1274  }
1275 
1276  /**
1277  Add a ad hoc (not "well-known") float value with the given key.
1278 
1279  @param key user-defined key (i.e. not wellknown). NTBS.
1280  @param val value.
1281 
1282  @retval the LogEvent, for easy fluent-style chaining.
1283  */
1284  LogEvent &float_value(const char *key, double val) {
1287  val);
1288  return *this;
1289  }
1290 
1291  /**
1292  Add a ad hoc string value with the given key.
1293 
1294  @param key user-defined key (i.e. not wellknown). NTBS.
1295  @param val value.
1296  @param len length in bytes of the value.
1297 
1298  @retval the LogEvent, for easy fluent-style chaining.
1299  */
1300  LogEvent &string_value(const char *key, const char *val, size_t len) {
1304  val, len);
1305  return *this;
1306  }
1307 
1308  /**
1309  Add a ad hoc string value with the given key.
1310 
1311  @param key user-defined key (i.e. not wellknown). NTBS.
1312  @param val value. NTBS.
1313 
1314  @retval the LogEvent, for easy fluent-style chaining.
1315  */
1316  LogEvent &string_value(const char *key, const char *val) {
1320  val);
1321  return *this;
1322  }
1323 };
1324 
1325 inline void LogEvent::set_message_by_errcode(longlong errcode, va_list ap) {
1326  const char *fmt = error_msg_by_errcode((int)errcode);
1327 
1328  if ((fmt == nullptr) || (*fmt == '\0')) fmt = "invalid error code";
1329 
1331  set_message(fmt, ap);
1332 }
1333 
1334 inline void LogEvent::set_message(const char *fmt, va_list ap) {
1335  if ((ll != nullptr) && (msg != nullptr)) {
1336  char buf[LOG_BUFF_MAX];
1337  if (msg_tag != nullptr) {
1338  snprintf(buf, LOG_BUFF_MAX - 1, "%s: \'%s\'", msg_tag, fmt);
1339  fmt = buf;
1340  }
1341  size_t len = log_msg(msg, LOG_BUFF_MAX - 1, fmt, ap);
1343  len);
1344  }
1345 }
1346 
1347 inline LogEvent &LogEvent::message(const char *fmt, ...) {
1348  va_list args;
1349  va_start(args, fmt);
1350  set_message(fmt, args);
1351  va_end(args);
1352 
1353  return *this;
1354 }
1355 
1356 // Methods initialize and de-initialize logging service for plugins.
1357 #if defined(MYSQL_DYNAMIC_PLUGIN)
1358 
1359 /**
1360  Method to de-initialize logging service in plugin.
1361 
1362  param[in,out] reg_srv Plugin registry service.
1363  param[in,out] log_bi Error logging service.
1364  param[in,out] log_bs String service for error logging.
1365 */
1366 inline void deinit_logging_service_for_plugin(
1367  SERVICE_TYPE(registry) * *reg_srv, SERVICE_TYPE(log_builtins) * *log_bi,
1368  SERVICE_TYPE(log_builtins_string) * *log_bs) {
1369  using log_builtins_t = SERVICE_TYPE_NO_CONST(log_builtins);
1370  using log_builtins_string_t = SERVICE_TYPE_NO_CONST(log_builtins_string);
1371  if (*log_bi)
1372  (*reg_srv)->release(
1373  reinterpret_cast<my_h_service>(const_cast<log_builtins_t *>(*log_bi)));
1374  if (*log_bs)
1375  (*reg_srv)->release(reinterpret_cast<my_h_service>(
1376  const_cast<log_builtins_string_t *>(*log_bs)));
1378  *log_bi = nullptr;
1379  *log_bs = nullptr;
1380  *reg_srv = nullptr;
1381 }
1382 
1383 /**
1384  Method to de-initialize logging service in plugin.
1385 
1386  param[in,out] reg_srv Plugin registry service.
1387  param[in,out] log_bi Error logging service.
1388  param[in,out] log_bs String service for error logging.
1389 
1390  @retval false Success.
1391  @retval true Failed.
1392 */
1393 inline bool init_logging_service_for_plugin(
1394  SERVICE_TYPE(registry) * *reg_srv, SERVICE_TYPE(log_builtins) * *log_bi,
1395  SERVICE_TYPE(log_builtins_string) * *log_bs) {
1396  my_h_service log_srv = nullptr;
1397  my_h_service log_str_srv = nullptr;
1399  if (!(*reg_srv)->acquire("log_builtins.mysql_server", &log_srv) &&
1400  !(*reg_srv)->acquire("log_builtins_string.mysql_server", &log_str_srv)) {
1401  (*log_bi) = reinterpret_cast<SERVICE_TYPE(log_builtins) *>(log_srv);
1402  (*log_bs) =
1403  reinterpret_cast<SERVICE_TYPE(log_builtins_string) *>(log_str_srv);
1404  } else {
1405  deinit_logging_service_for_plugin(reg_srv, log_bi, log_bs);
1406  return true;
1407  }
1408  return false;
1409 }
1410 
1411 #elif defined(EXTRA_CODE_FOR_UNIT_TESTING)
1412 
1413 /**
1414  Method is used by unit tests.
1415 
1416  param[in,out] reg_srv Plugin registry service.
1417  param[in,out] log_bi Error logging service.
1418  param[in,out] log_bs String service for error logging.
1419 
1420  @retval false Success.
1421  @retval true Failed.
1422 */
1423 inline bool init_logging_service_for_plugin(
1424  SERVICE_TYPE(registry) * *reg_srv MY_ATTRIBUTE((unused)),
1425  SERVICE_TYPE(log_builtins) * *log_bi MY_ATTRIBUTE((unused)),
1426  SERVICE_TYPE(log_builtins_string) * *log_bs MY_ATTRIBUTE((unused)))
1427 
1428 {
1429  return false;
1430 }
1431 
1432 /**
1433  Method is used by unit tests.
1434 
1435  param[in,out] reg_srv Plugin registry service.
1436  param[in,out] log_bi Error logging service.
1437  param[in,out] log_bs String service for error logging.
1438 */
1439 inline void deinit_logging_service_for_plugin(
1440  SERVICE_TYPE(registry) * *reg_srv MY_ATTRIBUTE((unused)),
1441  SERVICE_TYPE(log_builtins) * *log_bi MY_ATTRIBUTE((unused)),
1442  SERVICE_TYPE(log_builtins_string) * *log_bs MY_ATTRIBUTE((unused))) {}
1443 
1444 #endif // MYSQL_DYNAMIC_PLUGIN
1445 
1446 #endif // __cplusplus
1447 
1448 #endif
#define log_set_lexstring
Definition: log_builtins.h:661
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:1316
Definition: log_shared.h:177
LogEvent & lookup_quoted(longlong errcode, const char *tag,...)
Definition: log_builtins.h:1243
#define free(A)
Definition: fts0ast.h:42
LogEvent & host(const char *val)
Whose session did the issue appear in?
Definition: log_builtins.h:1049
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:1269
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:803
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:662
#define log_free
Definition: log_builtins.h:664
Definition: log_shared.h:183
~LogEvent()
Destructor automatically sends the event on.
Definition: log_builtins.h:838
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:1143
integer not otherwise specified
Definition: log_shared.h:153
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:1194
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:213
LogEvent & type(enum_log_type val)
Set log type.
Definition: log_builtins.h:873
log_line ("log event")
Definition: log_builtins_imp.h:85
SQL state.
Definition: log_shared.h:131
#define log_line_exit
Definition: log_builtins.h:654
#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
void log_sink_buffer_check_timeout(void)
Convenience function.
Definition: log_builtins.cc:1495
const char * msg_tag
Definition: log_builtins.h:793
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:1254
#define DECLARE_METHOD(retval, name, args)
LogEvent & errcode(longlong val)
Append a numeric error code.
Definition: log_builtins.h:885
char * msg
Definition: log_builtins.h:792
LogEvent & thread_id(longlong val)
What thread / "connection ID" was the issue detected in?
Definition: log_builtins.h:1061
#define log_line_init
Definition: log_builtins.h:653
#define log_line_item_set_with_key
Definition: log_builtins.h:655
LogEvent & source_line(longlong val)
Which line in the source file was the problem detected on?
Definition: log_builtins.h:958
LogEvent()
"Full customization" constructor.
Definition: log_builtins.h:854
void set_message(const char *fmt, va_list ap)
Set the error message.
Definition: log_builtins.h:1334
size_t length
Definition: mysql_lex_string.h:41
#define LOG_BUFF_MAX
advisory.
Definition: log_shared.h:222
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:1347
Header for compiler-dependent features.
#define SERVICE_TYPE_NO_CONST(name)
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:1217
float not otherwise specified
Definition: log_shared.h:152
unsigned int uint
Definition: uca-dump.cc:29
LogEvent & lookupv(longlong errcode, va_list args)
Find an error message by its MySQL error code.
Definition: log_builtins.h:1237
LogEvent & host(LEX_CSTRING val)
Whose session did the issue appear in?
Definition: log_builtins.h:1036
LogEvent & query_id(longlong val)
What query apparently caused the issue?
Definition: log_builtins.h:1073
long long int longlong
Definition: my_inttypes.h:73
log called from function ...
Definition: log_shared.h:136
t
Definition: dbug_analyze.cc:147
uint32_t uint32
Definition: my_inttypes.h:62
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:1325
#define BEGIN_SERVICE_DEFINITION(name)
#define log_line_item_types_seen
Definition: log_builtins.h:657
LogEvent & os_errmsg(const char *val)
Append a textual (operating system, as opposed to MySQL) error message, vulgo, strerror() ...
Definition: log_builtins.h:934
LogEvent & sqlstate(const char *val)
Append a (string) SQL state.
Definition: log_builtins.h:909
#define log_set_int
Definition: log_builtins.h:659
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:1108
LogEvent & errsymbol(const char *val)
Append a (string) error symbol.
Definition: log_builtins.h:897
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:1284
lex string not otherwise specified
Definition: log_shared.h:154
query ID
Definition: log_shared.h:142
#define log_msg
Definition: log_builtins.h:665
LogEvent & user(const char *val)
What user were we working for at the time of the issue?
Definition: log_builtins.h:1024
Definition: log_shared.h:193
LogEvent & label(const char *val)
Set a label (usually "warning"/"error"/"information").
Definition: log_builtins.h:1122
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:77
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:1300
LogEvent & os_errno(longlong val)
Append a numeric (operating system, as opposed to MySQL) error number.
Definition: log_builtins.h:921
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:660
table name
Definition: log_shared.h:143
char * strndup(const char *s, size_t n)
The strndup() function returns a pointer to a new string which is a duplicate of the string s...
Definition: wrapper_functions.h:96
LogEvent & source_file(const char *val)
Which source file was the problem detected in?
Definition: log_builtins.h:946
LogEvent & user(LEX_CSTRING val)
What user were we working for at the time of the issue?
Definition: log_builtins.h:1011
#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:791
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:998
#define error_msg_by_errcode
Definition: log_builtins.h:666
LogEvent & subsys(const char *val)
Which subsystem in the source was the problem detected in? ("Repl"/"InnoDB"/"Server") ...
Definition: log_builtins.h:983
Specifies macros to define Service Implementations.
error log, etc.
Definition: log_shared.h:128
Modular logger: fluid API.
Definition: log_builtins.h:789
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:658
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:102
LogEvent & table_name(const char *val)
What table were we working on?
Definition: log_builtins.h:1085
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:46
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:1160
#define log_line_item_set
Definition: log_builtins.h:656
#define log_malloc
Definition: log_builtins.h:663