MySQL 8.4.2
Source Code Documentation
|
Primitives for services to interact with the structured logger: functions pertaining to log_line and log_item data. 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 *(* | line_get_output_buffer )(log_line *ll) |
Get log-line's output buffer. 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... | |
ulonglong(* | parse_iso8601_timestamp )(const char *timestamp, size_t len) |
Parse a ISO8601 timestamp and return the number of microseconds since the epoch. More... | |
log_service_error(* | open_errstream )(const char *name_or_ext, void **my_errstream) |
open an error log file More... | |
log_service_error(* | 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... | |
log_service_error(* | close_errstream )(void **my_errstream) |
close an error log file previously opened with open_errstream() More... | |
log_service_error(* | reopen_errstream )(const char *file, void **my_errstream) |
re-open an error log file (primarily to facilitate flush/log-rotation) More... | |
Primitives for services to interact with the structured logger: functions pertaining to log_line and log_item data.
log_service_error(* s_mysql_log_builtins::close_errstream) (void **my_errstream) |
close an error log file previously opened with open_errstream()
my_stream | a handle describing the log file |
int(* s_mysql_log_builtins::dedicated_errstream) (void *my_errstream) |
are we writing to a dedicated errstream, or are we sharing it?
my_errstream | a handle describing the log file |
0 | not dedicated (multiplexed, stderr, ...) |
1 | dedicated |
longlong(* s_mysql_log_builtins::errcode_by_errsymbol) (const char *sym) |
Return MySQL error code for a given error symbol.
sym | the symbol to look up |
-1 | failure |
>=0 | the MySQL error code |
const char *(* s_mysql_log_builtins::errmsg_by_errcode) (int mysql_errcode) |
Return MySQL error message for a given error code.
mysql_errcode | the error code the message for which to look up |
the | message (a printf-style format string) |
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.
t | log item type to examine |
true | if generic type |
false | if wellknown type |
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.
li | the log_item to check |
LOG_ITEM_OK | no problems |
LOG_ITEM_TYPE_NOT_FOUND | unknown item type |
LOG_ITEM_CLASS_MISMATCH | item_class derived from type isn't what's set on the item |
LOG_ITEM_KEY_MISMATCH | class not generic, so key should match wellknown |
LOG_ITEM_STRING_NULL | class is string, pointer is nullptr |
LOG_ITEM_KEY_NULL | no 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) |
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).
c | log item class to examine |
true | if of a numeric class |
false | if not of a numeric class |
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.
li | the log_item to work on |
t | the item-type |
a | pointer to the log_item's log_data, for easy chaining: log_item_set_with_key(...)->data_integer= 1; |
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]().
lid | log_item_data struct to set the value on |
s | pointer to NTBS |
true | lid was nullptr (possibly: OOM, could not set up log_item) |
false | all's well |
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]().
lid | log_item_data struct to set the value on |
f | float to set |
true | lid was nullptr (possibly: OOM, could not set up log_item) |
false | all's well |
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]().
lid | log_item_data struct to set the value on |
i | integer to set |
true | lid was nullptr (possibly: OOM, could not set up log_item) |
false | all's well |
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]().
lid | log_item_data struct to set the value on |
s | pointer to string |
s_len | length of string |
true | lid was nullptr (possibly: OOM, could not set up log_item) |
false | all's well |
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.
li | the log_item to work on |
t | the item-type |
key | the key to set on the item. ignored for non-generic types (may pass nullptr for those) see alloc |
alloc | LOG_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. |
a | pointer to the log_item's log_data, for easy chaining: log_item_set_with_key(...)->data_integer= 1; |
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).
c | log item class to examine |
true | if of a string class |
false | if not of a string class |
const char *(* s_mysql_log_builtins::label_from_prio) (int prio) |
Convenience function: Derive a log label ("error", "warning", "information") from a severity.
prio | the severity/prio in question |
System | for prio of SYSTEM_LEVEL |
Error | for prio of ERROR_LEVEL |
Warning | for prio of WARNING_LEVEL |
Note | for prio of INFORMATION_LEVEL |
void(* s_mysql_log_builtins::line_exit) (log_line *ll) |
Release a log_line allocated with line_init()
ll | a log_line previously allocated with line_init() |
Get log-line's output buffer.
If the logger core provides this buffer, the log-service may use it to assemble its output therein and implicitly return it to the core. Participation is required for services that support populating performance_schema.error_log, and optional for all others.
ll | the log_line to examine |
nullptr | success, an output buffer is available |
otherwise | failure, no output buffer is available |
log_line *(* s_mysql_log_builtins::line_init) () |
Dynamically allocate and initialize a log_line.
nullptr | could not set up buffer (too small?) |
other | address of the newly initialized log_line |
int(* s_mysql_log_builtins::line_item_count) (log_line *ll) |
How many items are currently set on the given log_line?
ll | the log-line to examine |
the | number of items set |
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.
ll | the log_line to examine |
a | log_iter_iter, or nullptr on failure |
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.
it | the iterator to use |
pointer | to the current log_item in the collection, or nullptr |
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.
it | the iterator to use |
pointer | to the first log_item in the collection, or nullptr |
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.
it | the iterator to use |
pointer | to the next log_item in the collection, or nullptr |
void(* s_mysql_log_builtins::line_item_iter_release) (log_item_iter *it) |
Release an iterator for the items in a log_line.
it | the iterator to release |
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.
ll | the log_line to work on |
t | the item-type |
a | pointer to the log_item's log_data, for easy chaining: log_line_item_set_with_key(...)->data_integer= 1; |
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.
ll | the log_line to work on |
t | the item-type |
key | the key to set on the item. ignored for non-generic types (may pass nullptr for those) see alloc |
alloc | LOG_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. |
a | pointer to the log_item's log_data, for easy chaining: log_line_item_set_with_key(...)->data_integer= 1; |
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.
ll | the log_line to examine |
m | the log_type to test for |
0 | not present |
!=0 | present |
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.
ll | key/value pairs describing info to log |
int | number of fields in created log line |
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
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
see log_vmessage() for more information.
log_service_error(* s_mysql_log_builtins::open_errstream) (const char *name_or_ext, void **my_errstream) |
open an error log file
name_or_ext | if 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!
[out] | my_errstream | an error log handle, or nullptr on failure |
ulonglong(* s_mysql_log_builtins::parse_iso8601_timestamp) (const char *timestamp, size_t len) |
Parse a ISO8601 timestamp and return the number of microseconds since the epoch.
Heeds +/- timezone info if present.
timestamp | an ASCII string containing an ISO8601 timestamp |
len | Length in bytes of the aforementioned string |
log_service_error(* s_mysql_log_builtins::reopen_errstream) (const char *file, void **my_errstream) |
re-open an error log file (primarily to facilitate flush/log-rotation)
If the new file can be opened, update the my_errstream descriptor to use it and close the old file. Otherwise, keep using the old file.
name_or_ext | if beginning with '.': @global.log_error, except with this extension otherwise: use this as file name in the same location as @global.log_error |
Value may not contain folder separators!
In the general case, the caller will be a log-writer, the log-writer will just pass its preferred file extension, and the resulting file name and path will therefore be the same as for the original log file.
[in,out] | my_errstream | an error log handle |
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.
li | list_item to process |
-1 | out of memory |
0 | success |
int(* s_mysql_log_builtins::wellknown_by_name) (const char *key, size_t length) |
See whether a string is a wellknown field name.
key | potential key starts here |
length | length of the string to examine |
LOG_ITEM_TYPE_RESERVED | reserved, but not "wellknown" key |
LOG_ITEM_TYPE_NOT_FOUND | key not found |
>0 | index in array of wellknowns |
int(* s_mysql_log_builtins::wellknown_by_type) (log_item_type t) |
See whether a type is wellknown.
t | log item type to examine |
LOG_ITEM_TYPE_NOT_FOUND | key not found |
>0 | index in array of wellknowns |
const char *(* s_mysql_log_builtins::wellknown_get_name) (uint idx) |
Accessor: from a record describing a wellknown key, get its name.
idx | index in array of wellknowns, see log_item_wellknown_by_...() |
name | (NTBS) |
log_item_type(* s_mysql_log_builtins::wellknown_get_type) (uint idx) |
Accessor: from a record describing a wellknown key, get its type.
idx | index in array of wellknowns, see log_item_wellknown_by_...() |
the | log item type for the wellknown key |
log_service_error(* 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()
my_errstream | a handle describing the log file |
buffer | pointer to the string to write |
length | length of the string to write |