MySQL  8.0.17
Source Code Documentation
s_mysql_log_builtins Struct Reference

This defines built-in functions for use by logging services. More...

#include <log_builtins.h>

Public Attributes

int(* wellknown_by_type )(log_item_type t)
 See whether a type is wellknown. More...
 
int(* wellknown_by_name )(const char *key, size_t length)
 See whether a string is a wellknown field name. More...
 
log_item_type(* wellknown_get_type )(uint idx)
 Accessor: from a record describing a wellknown key, get its type. More...
 
const char *(* wellknown_get_name )(uint idx)
 Accessor: from a record describing a wellknown key, get its name. More...
 
int(* item_inconsistent )(log_item *li)
 Sanity check an item. More...
 
bool(* item_generic_type )(log_item_type t)
 Predicate used to determine whether a type is generic (generic string, generic float, generic integer) rather than a well-known type. More...
 
bool(* item_string_class )(log_item_class c)
 Predicate used to determine whether a class is a string class (C-string or Lex-string). More...
 
bool(* item_numeric_class )(log_item_class c)
 Predicate used to determine whether a class is a numeric class (integer or float). More...
 
bool(* item_set_int )(log_item_data *lid, longlong i)
 Set an integer value on a log_item. More...
 
bool(* item_set_float )(log_item_data *lid, double f)
 Set a floating point value on a log_item. More...
 
bool(* item_set_lexstring )(log_item_data *lid, const char *s, size_t s_len)
 Set a string value on a log_item. More...
 
bool(* item_set_cstring )(log_item_data *lid, const char *s)
 Set a string value on a log_item. More...
 
log_item_data *(* item_set_with_key )(log_item *li, log_item_type t, const char *key, uint32 alloc)
 Create new log item with key name "key", and allocation flags of "alloc" (see enum_log_item_free). More...
 
log_item_data *(* item_set )(log_item *li, log_item_type t)
 As log_item_set_with_key(), except that the key is automatically derived from the wellknown log_item_type t. More...
 
log_item_data *(* line_item_set_with_key )(log_line *ll, log_item_type t, const char *key, uint32 alloc)
 Create new log item in log line "ll", with key name "key", and allocation flags of "alloc" (see enum_log_item_free). More...
 
log_item_data *(* line_item_set )(log_line *ll, log_item_type t)
 Create a new log item of well-known type "t" in log line "ll". More...
 
log_line *(* line_init )()
 Dynamically allocate and initialize a log_line. More...
 
void(* line_exit )(log_line *ll)
 Release a log_line allocated with line_init() More...
 
int(* line_item_count )(log_line *ll)
 How many items are currently set on the given log_line? More...
 
log_item_type_mask(* line_item_types_seen )(log_line *ll, log_item_type_mask m)
 Test whether a given type is presumed present on the log line. More...
 
log_item_iter *(* line_item_iter_acquire )(log_line *ll)
 Get an iterator for the items in a log_line. More...
 
void(* line_item_iter_release )(log_item_iter *it)
 Release an iterator for the items in a log_line. More...
 
log_item *(* line_item_iter_first )(log_item_iter *it)
 Use the log_line iterator to get the first item from the set. More...
 
log_item *(* line_item_iter_next )(log_item_iter *it)
 Use the log_line iterator to get the next item from the set. More...
 
log_item *(* line_item_iter_current )(log_item_iter *it)
 Use the log_line iterator to get the current item from the set. More...
 
int(* line_submit )(log_line *ll)
 Complete, filter, and write submitted log items. More...
 
int(* message )(int log_type,...)
 Submit a log-message for log "log_type". More...
 
int(* sanitize )(log_item *li)
 Escape \0 bytes, add \0 terminator. More...
 
const char *(* errmsg_by_errcode )(int mysql_errcode)
 Return MySQL error message for a given error code. More...
 
longlong(* errcode_by_errsymbol )(const char *sym)
 Return MySQL error code for a given error symbol. More...
 
const char *(* label_from_prio )(int prio)
 Convenience function: Derive a log label ("error", "warning", "information") from a severity. More...
 
int(* open_errstream )(const char *file, void **my_errstream)
 open an error log file More...
 
int(* write_errstream )(void *my_errstream, const char *buffer, size_t length)
 write to an error log file previously opened with open_errstream() More...
 
int(* dedicated_errstream )(void *my_errstream)
 are we writing to a dedicated errstream, or are we sharing it? More...
 
int(* close_errstream )(void **my_errstream)
 close an error log file previously opened with open_errstream() More...
 

Detailed Description

This defines built-in functions for use by logging services.

These helpers are organized into a number of APIs grouping related functionality.

For documentation of the individual functions, see log_builtins.cc Primitives for services to interact with the structured logger: functions pertaining to log_line and log_item data

Member Data Documentation

◆ close_errstream

int(* s_mysql_log_builtins::close_errstream) (void **my_errstream)

close an error log file previously opened with open_errstream()

Parameters
my_streama handle describing the log file
Return values
0success
!0failure

◆ dedicated_errstream

int(* s_mysql_log_builtins::dedicated_errstream) (void *my_errstream)

are we writing to a dedicated errstream, or are we sharing it?

Parameters
my_errstreama handle describing the log file
Return values
0not dedicated (multiplexed, stderr, ...)
1dedicated

◆ errcode_by_errsymbol

longlong(* s_mysql_log_builtins::errcode_by_errsymbol) (const char *sym)

Return MySQL error code for a given error symbol.

Parameters
symthe symbol to look up
Return values
-1failure
>=0the MySQL error code

◆ errmsg_by_errcode

const char*(* s_mysql_log_builtins::errmsg_by_errcode) (int mysql_errcode)

Return MySQL error message for a given error code.

Parameters
mysql_errcodethe error code the message for which to look up
Return values
themessage (a printf-style format string)

◆ item_generic_type

bool(* s_mysql_log_builtins::item_generic_type) (log_item_type t)

Predicate used to determine whether a type is generic (generic string, generic float, generic integer) rather than a well-known type.

Parameters
tlog item type to examine
Return values
trueif generic type
falseif wellknown type

◆ item_inconsistent

int(* s_mysql_log_builtins::item_inconsistent) (log_item *li)

Sanity check an item.

Certain log sinks have very low requirements with regard to the data they receive; they write keys as strings, and then data according to the item's class (string, integer, or float), formatted to the sink's standards (e.g. JSON, XML, ...). Code that has higher requirements can use this check to see whether the given item is of a known type (whether generic or wellknown), whether the given type and class agree, and whether in case of a well-known type, the given key is correct for that type. If your code generates items that don't pass this check, you should probably go meditate on it.

Parameters
lithe log_item to check
Return values
LOG_ITEM_OKno problems
LOG_ITEM_TYPE_NOT_FOUNDunknown item type
LOG_ITEM_CLASS_MISMATCHitem_class derived from type isn't what's set on the item
LOG_ITEM_KEY_MISMATCHclass not generic, so key should match wellknown
LOG_ITEM_STRING_NULLclass is string, pointer is nullptr
LOG_ITEM_KEY_NULLno key set (this is legal e.g. on aux items of filter rules, but should not occur in a log_line, i.e., log_sinks are within their rights to discard such items)

◆ item_numeric_class

bool(* s_mysql_log_builtins::item_numeric_class) (log_item_class c)

Predicate used to determine whether a class is a numeric class (integer or float).

Parameters
clog item class to examine
Return values
trueif of a numeric class
falseif not of a numeric class

◆ item_set

log_item_data*(* s_mysql_log_builtins::item_set) (log_item *li, log_item_type t)

As log_item_set_with_key(), except that the key is automatically derived from the wellknown log_item_type t.

Create new log item with type "t". Will return a pointer to the item's log_item_data struct for convenience. This is mostly interesting for filters and other services that create items that are not part of a log_line; sources etc. that intend to create an item for a log_line (the more common case) should usually use the below line_item_set_with_key() which creates an item (like this function does), but also correctly inserts it into a log_line.

The allocation of this item will be LOG_ITEM_FREE_NONE; specifically, any pre-existing value will be clobbered. It is therefore WRONG a) to use this on a log_item that already has a key; it should only be used on freshly init'd log_items; b) to use this on a log_item that already has a value (specifically, an allocated one); the correct order is to init a log_item, then set up type and key, and finally to set the value. If said value is an allocated string, the log_item's alloc should be bitwise or'd with LOG_ITEM_FREE_VALUE.

Parameters
lithe log_item to work on
tthe item-type
Return values
apointer to the log_item's log_data, for easy chaining: log_item_set_with_key(...)->data_integer= 1;

◆ item_set_cstring

bool(* s_mysql_log_builtins::item_set_cstring) (log_item_data *lid, const char *s)

Set a string value on a log_item.

Fails gracefully if no log_item_data is supplied, so it can safely wrap log_line_item_set[_with_key]().

Parameters
lidlog_item_data struct to set the value on
spointer to NTBS
Return values
truelid was nullptr (possibly: OOM, could not set up log_item)
falseall's well

◆ item_set_float

bool(* s_mysql_log_builtins::item_set_float) (log_item_data *lid, double f)

Set a floating point value on a log_item.

Fails gracefully if no log_item_data is supplied, so it can safely wrap log_line_item_set[_with_key]().

Parameters
lidlog_item_data struct to set the value on
ffloat to set
Return values
truelid was nullptr (possibly: OOM, could not set up log_item)
falseall's well

◆ item_set_int

bool(* s_mysql_log_builtins::item_set_int) (log_item_data *lid, longlong i)

Set an integer value on a log_item.

Fails gracefully if no log_item_data is supplied, so it can safely wrap log_line_item_set[_with_key]().

Parameters
lidlog_item_data struct to set the value on
iinteger to set
Return values
truelid was nullptr (possibly: OOM, could not set up log_item)
falseall's well

◆ item_set_lexstring

bool(* s_mysql_log_builtins::item_set_lexstring) (log_item_data *lid, const char *s, size_t s_len)

Set a string value on a log_item.

Fails gracefully if no log_item_data is supplied, so it can safely wrap log_line_item_set[_with_key]().

Parameters
lidlog_item_data struct to set the value on
spointer to string
s_lenlength of string
Return values
truelid was nullptr (possibly: OOM, could not set up log_item)
falseall's well

◆ item_set_with_key

log_item_data*(* s_mysql_log_builtins::item_set_with_key) (log_item *li, log_item_type t, const char *key, uint32 alloc)

Create new log item with key name "key", and allocation flags of "alloc" (see enum_log_item_free).

Will return a pointer to the item's log_item_data struct for convenience. This is mostly interesting for filters and other services that create items that are not part of a log_line; sources etc. that intend to create an item for a log_line (the more common case) should usually use the below line_item_set_with_key() which creates an item (like this function does), but also correctly inserts it into a log_line.

Parameters
lithe log_item to work on
tthe item-type
keythe key to set on the item. ignored for non-generic types (may pass nullptr for those) see alloc
allocLOG_ITEM_FREE_KEY if key was allocated by caller LOG_ITEM_FREE_NONE if key was not allocated Allocated keys will automatically free()d when the log_item is. The log_item's alloc flags will be set to the submitted value; specifically, any pre-existing value will be clobbered. It is therefore WRONG a) to use this on a log_item that already has a key; it should only be used on freshly init'd log_items; b) to use this on a log_item that already has a value (specifically, an allocated one); the correct order is to init a log_item, then set up type and key, and finally to set the value. If said value is an allocated string, the log_item's alloc should be bitwise or'd with LOG_ITEM_FREE_VALUE.
Return values
apointer to the log_item's log_data, for easy chaining: log_item_set_with_key(...)->data_integer= 1;

◆ item_string_class

bool(* s_mysql_log_builtins::item_string_class) (log_item_class c)

Predicate used to determine whether a class is a string class (C-string or Lex-string).

Parameters
clog item class to examine
Return values
trueif of a string class
falseif not of a string class

◆ label_from_prio

const char*(* s_mysql_log_builtins::label_from_prio) (int prio)

Convenience function: Derive a log label ("error", "warning", "information") from a severity.

Parameters
priothe severity/prio in question
Returns
a label corresponding to that priority.
Return values
Systemfor prio of SYSTEM_LEVEL
Errorfor prio of ERROR_LEVEL
Warningfor prio of WARNING_LEVEL
Notefor prio of INFORMATION_LEVEL

◆ line_exit

void(* s_mysql_log_builtins::line_exit) (log_line *ll)

Release a log_line allocated with line_init()

Parameters
lla log_line previously allocated with line_init()

◆ line_init

log_line*(* s_mysql_log_builtins::line_init) ()

Dynamically allocate and initialize a log_line.

Return values
nullptrcould not set up buffer (too small?)
otheraddress of the newly initialized log_line

◆ line_item_count

int(* s_mysql_log_builtins::line_item_count) (log_line *ll)

How many items are currently set on the given log_line?

Parameters
llthe log-line to examine
Return values
thenumber of items set

◆ line_item_iter_acquire

log_item_iter*(* s_mysql_log_builtins::line_item_iter_acquire) (log_line *ll)

Get an iterator for the items in a log_line.

For now, only one iterator may exist per log_line.

Parameters
llthe log_line to examine
Return values
alog_iterm_iter, or nullptr on failure

◆ line_item_iter_current

log_item*(* s_mysql_log_builtins::line_item_iter_current) (log_item_iter *it)

Use the log_line iterator to get the current item from the set.

Parameters
itthe iterator to use
Return values
pointerto the current log_item in the collection, or nullptr

◆ line_item_iter_first

log_item*(* s_mysql_log_builtins::line_item_iter_first) (log_item_iter *it)

Use the log_line iterator to get the first item from the set.

Parameters
itthe iterator to use
Return values
pointerto the first log_item in the collection, or nullptr

◆ line_item_iter_next

log_item*(* s_mysql_log_builtins::line_item_iter_next) (log_item_iter *it)

Use the log_line iterator to get the next item from the set.

Parameters
itthe iterator to use
Return values
pointerto the next log_item in the collection, or nullptr

◆ line_item_iter_release

void(* s_mysql_log_builtins::line_item_iter_release) (log_item_iter *it)

Release an iterator for the items in a log_line.

Parameters
itthe iterator to release

◆ line_item_set

log_item_data*(* s_mysql_log_builtins::line_item_set) (log_line *ll, log_item_type t)

Create a new log item of well-known type "t" in log line "ll".

On success, the number of registered items on the log line is increased, the item's type is added to the log_line's "seen" property, and a pointer to the item's log_item_data struct is returned for convenience.

The allocation of this item will be LOG_ITEM_FREE_NONE; specifically, any pre-existing value will be clobbered. It is therefore WRONG a) to use this on a log_item that already has a key; it should only be used on freshly init'd log_items; b) to use this on a log_item that already has a value (specifically, an allocated one); the correct order is to init a log_item, then set up type and key, and finally to set the value. If said value is an allocated string, the log_item's alloc should be bitwise or'd with LOG_ITEM_FREE_VALUE.

Parameters
llthe log_line to work on
tthe item-type
Return values
apointer to the log_item's log_data, for easy chaining: log_line_item_set_with_key(...)->data_integer= 1;

◆ line_item_set_with_key

log_item_data*(* s_mysql_log_builtins::line_item_set_with_key) (log_line *ll, log_item_type t, const char *key, uint32 alloc)

Create new log item in log line "ll", with key name "key", and allocation flags of "alloc" (see enum_log_item_free).

On success, the number of registered items on the log line is increased, the item's type is added to the log_line's "seen" property, and a pointer to the item's log_item_data struct is returned for convenience.

Parameters
llthe log_line to work on
tthe item-type
keythe key to set on the item. ignored for non-generic types (may pass nullptr for those) see alloc
allocLOG_ITEM_FREE_KEY if key was allocated by caller LOG_ITEM_FREE_NONE if key was not allocated Allocated keys will automatically free()d when the log_item is. The log_item's alloc flags will be set to the submitted value; specifically, any pre-existing value will be clobbered. It is therefore WRONG a) to use this on a log_item that already has a key; it should only be used on freshly init'd log_items; b) to use this on a log_item that already has a value (specifically, an allocated one); the correct order is to init a log_item, then set up type and key, and finally to set the value. If said value is an allocated string, the log_item's alloc should be bitwise or'd with LOG_ITEM_FREE_VALUE.
Return values
apointer to the log_item's log_data, for easy chaining: log_line_item_set_with_key(...)->data_integer= 1;

◆ line_item_types_seen

log_item_type_mask(* s_mysql_log_builtins::line_item_types_seen) (log_line *ll, log_item_type_mask m)

Test whether a given type is presumed present on the log line.

Parameters
llthe log_line to examine
mthe log_type to test for
Return values
0not present
!=0present

◆ line_submit

int(* s_mysql_log_builtins::line_submit) (log_line *ll)

Complete, filter, and write submitted log items.

This expects a log_line collection of log-related key/value pairs, e.g. from log_message().

Where missing, timestamp, priority, thread-ID (if any) and so forth are added.

Log item source services, log item filters, and log item sinks are then called; then all applicable resources are freed.

This interface is intended to facilitate the building of submission interfaces other than the variadic message() one below. See the example fluent C++ LogEvent() wrapper for an example of how to leverage it.

Parameters
llkey/value pairs describing info to log
Return values
intnumber of fields in created log line

◆ message

int(* s_mysql_log_builtins::message) (int log_type,...)

Submit a log-message for log "log_type".

Variadic convenience function for logging.

This fills in the array that is used by the filter and log-writer services. Where missing, timestamp, priority, and thread-ID (if any) are added. Log item source services, log item filters, and log item writers are called.

The variadic list accepts a list of "assignments" of the form

  • log_item_type, value, for well-known types, and
  • log_item_type, key, value, for ad-hoc types (LOG_ITEM_GEN_*)

As its last item, the list should have

  • an element of type LOG_ITEM_LOG_MESSAGE, containing a printf-style format string, followed by all variables necessary to satisfy the substitutions in that string

    OR

  • an element of type LOG_ITEM_LOG_LOOKUP, containing a MySQL error code, which will be looked up in the list or regular error messages, followed by all variables necessary to satisfy the substitutions in that string

    OR

  • an element of type LOG_ITEM_LOG_VERBATIM, containing a string that will be used directly, with no % substitutions

see log_vmessage() for more information.

◆ open_errstream

int(* s_mysql_log_builtins::open_errstream) (const char *file, void **my_errstream)

open an error log file

Parameters
fileif beginning with '.': @global.log_error, except with this extension otherwise: use this as file name in the same location as @global.log_error

Value not contain folder separators!

Parameters
[out]my_errstreaman error log handle, or nullptr on failure
Return values
0success
!0failure

◆ sanitize

int(* s_mysql_log_builtins::sanitize) (log_item *li)

Escape \0 bytes, add \0 terminator.

For log-writers and other sinks that terminate in an API using C-strings.

Parameters
lilist_item to process
Return values
-1out of memory
0success

◆ wellknown_by_name

int(* s_mysql_log_builtins::wellknown_by_name) (const char *key, size_t length)

See whether a string is a wellknown field name.

Parameters
keypotential key starts here
lengthlength of the string to examine
Return values
LOG_ITEM_TYPE_RESERVEDreserved, but not "wellknown" key
LOG_ITEM_TYPE_NOT_FOUNDkey not found
>0index in array of wellknowns

◆ wellknown_by_type

int(* s_mysql_log_builtins::wellknown_by_type) (log_item_type t)

See whether a type is wellknown.

Parameters
tlog item type to examine
Return values
LOG_ITEM_TYPE_NOT_FOUNDkey not found
>0index in array of wellknowns

◆ wellknown_get_name

const char*(* s_mysql_log_builtins::wellknown_get_name) (uint idx)

Accessor: from a record describing a wellknown key, get its name.

Parameters
idxindex in array of wellknowns, see log_item_wellknown_by_...()
Return values
name(NTBS)

◆ wellknown_get_type

log_item_type(* s_mysql_log_builtins::wellknown_get_type) (uint idx)

Accessor: from a record describing a wellknown key, get its type.

Parameters
idxindex in array of wellknowns, see log_item_wellknown_by_...()
Return values
thelog item type for the wellknown key

◆ write_errstream

int(* s_mysql_log_builtins::write_errstream) (void *my_errstream, const char *buffer, size_t length)

write to an error log file previously opened with open_errstream()

Parameters
my_errstreama handle describing the log file
bufferpointer to the string to write
lengthlength of the string to write
Return values
0success
!0failure

The documentation for this struct was generated from the following file: