MySQL 8.4.2
Source Code Documentation
|
#include "log_builtins_filter_imp.h"
#include "log_builtins_imp.h"
#include "log_sink_buffer.h"
#include "log_sink_perfschema.h"
#include "log_sink_trad.h"
#include "m_string.h"
#include "mysys_err.h"
#include <mysql/components/services/log_shared.h>
#include "my_time.h"
#include "sql/current_thd.h"
#include "sql/log.h"
#include "sql/mysqld.h"
#include "sql/sql_class.h"
#include "sql/tztime.h"
#include "string_with_len.h"
#include "mysql/components/services/log_builtins.h"
#include <syslog.h>
Classes | |
struct | log_service_cache_entry_free |
struct | log_errstream |
An error-stream. More... | |
struct | _log_item_wellknown_key |
Pre-defined "well-known" keys, as opposed to ad hoc ones, for key/value pairs in logging. More... | |
Macros | |
#define | LOG_SUBSYSTEM_TAG "Server" |
#define | LOG_SERVICES_PREFIX "log_service" |
Name of the interface that log-services implements. More... | |
#define | LOG_SERVICES_URN "file://component_" |
URN-prefix used to load a log-component. More... | |
Typedefs | |
using | cache_entry_with_deleter = unique_ptr< log_service_cache_entry, log_service_cache_entry_free > |
We're caching handles to the services used in error logging as looking them up is costly. More... | |
typedef struct _log_item_wellknown_key | log_item_wellknown_key |
Pre-defined "well-known" keys, as opposed to ad hoc ones, for key/value pairs in logging. More... | |
Functions | |
bool | log_line_buffer_event (log_line *ll) |
Initial log-processor: Just buffer events until we have external log-components. More... | |
void | log_line_process_hook_set (log_line_processor llp) |
Set the log-event processor. More... | |
log_line_processor | log_line_process_hook_get (void) |
Get current log-event processor. More... | |
ulonglong | log_builtins_started () |
When the logger-core was initialized. More... | |
void | log_error_stage_set (enum log_error_stage les) |
Set error-logging stage hint (e.g. are loadable services available yet?). More... | |
enum log_error_stage | log_error_stage_get () |
What mode is error-logging in (e.g. are loadable services available yet)? More... | |
static int | log_service_check_if_builtin (const char *name, size_t len) |
Test whether a given log-service name refers to a built-in service (built-in filter or built-in sink at this point). More... | |
static bool | log_service_has_characteristics (log_service_cache_entry *sce, int required_flags) |
Test whether given service has all of the given characteristics. More... | |
int | log_string_compare (const char *a, const char *b, size_t len, bool case_insensitive) |
Modular logger: log line and key/value manipulation helpers. More... | |
bool | log_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 | log_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 | log_item_numeric_class (log_item_class c) |
Predicate used to determine whether a class is a numeric class (integer or float). More... | |
void | log_item_get_int (log_item *li, longlong *i) |
Get an integer value from a log-item of float or integer type. More... | |
void | log_item_get_float (log_item *li, double *f) |
Get a float value from a log-item of float or integer type. More... | |
void | log_item_get_string (log_item *li, char **str, size_t *len) |
Get a string value from a log-item of C-string or Lex string type. More... | |
int | log_item_wellknown_by_name (const char *key, size_t len) |
See whether a string is a wellknown field name. More... | |
int | log_item_wellknown_by_type (log_item_type t) |
See whether a type is wellknown. More... | |
const char * | log_item_wellknown_get_name (uint idx) |
Accessor: from a record describing a wellknown key, get its name. More... | |
log_item_type | log_item_wellknown_get_type (uint idx) |
Accessor: from a record describing a wellknown key, get its type. More... | |
log_item_class | log_item_wellknown_get_class (uint idx) |
Accessor: from a record describing a wellknown key, get its class. More... | |
int | log_item_inconsistent (log_item *li) |
Sanity check an item. More... | |
void | log_item_free (log_item *li) |
Release any of key and value on a log-item that were dynamically allocated. More... | |
log_line * | log_line_init () |
Initialize a log_line. More... | |
void | log_line_exit (log_line *ll) |
Release a log_line allocated with line_init() More... | |
log_item * | log_line_get_output_buffer (log_line *ll) |
Get log-line's output buffer. More... | |
bool | log_line_full (log_line *ll) |
Predicate indicating whether a log line is "willing" to accept any more key/value pairs. More... | |
int | log_line_item_count (log_line *ll) |
How many items are currently set on the given log_line? More... | |
log_item_type_mask | log_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... | |
void | log_line_item_free (log_line *ll, size_t elem) |
Release log line item (key/value pair) with the index elem in log line ll. More... | |
void | log_line_item_free_all (log_line *ll) |
Release all log line items (key/value pairs) in log line ll. More... | |
void | log_line_item_remove (log_line *ll, int elem) |
Release log line item (key/value pair) with the index elem in log line ll. More... | |
int | log_line_index_by_name (log_line *ll, const char *key) |
Find the (index of the) last key/value pair of the given name in the log line. More... | |
log_item * | log_line_item_by_name (log_line *ll, const char *key) |
Find the last item matching the given key in the log line. More... | |
int | log_line_index_by_type (log_line *ll, log_item_type t) |
Find the (index of the) first key/value pair of the given type in the log line. More... | |
int | log_line_index_by_item (log_line *ll, log_item *ref) |
Find the (index of the) first key/value pair of the given type in the log line. More... | |
void | log_item_init (log_item *li) |
Initializes a log entry for use. More... | |
log_item * | log_line_item_init (log_line *ll) |
Initializes an entry in a log line for use. More... | |
log_item_data * | log_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 * | log_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 * | log_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 * | log_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... | |
bool | log_item_set_int (log_item_data *lid, longlong i) |
Set an integer value on a log_item. More... | |
bool | log_item_set_float (log_item_data *lid, double f) |
Set a floating point value on a log_item. More... | |
bool | log_item_set_buffer (log_item_data *lid, char *s, size_t s_len) |
Set a string buffer on a log_item. More... | |
bool | log_item_set_lexstring (log_item_data *lid, const char *s, size_t s_len) |
Set a string value on a log_item. More... | |
bool | log_item_set_cstring (log_item_data *lid, const char *s) |
Set a string value on a log_item. More... | |
const char * | log_label_from_prio (int prio) |
Convenience function: Derive a log label ("error", "warning", "information") from a severity. More... | |
enum loglevel | log_prio_from_label (const char *label) |
Derive the event's priority (SYSTEM_LEVEL, ERROR_LEVEL, ...) from a textual label. More... | |
bool | log_line_error_stack_run (log_line *ll) |
MySQL server's default log-processor. More... | |
int | log_line_submit (log_line *ll) |
Complete, filter, and write submitted log items. More... | |
int | make_iso8601_timestamp (char *buf, ulonglong utime, enum enum_iso8601_tzmode mode) |
Make and return an ISO 8601 / RFC 3339 compliant timestamp. More... | |
ulonglong | iso8601_timestamp_to_microseconds (const char *timestamp, size_t len) |
Parse a ISO8601 timestamp and return the number of microseconds since the epoch. More... | |
static ssize_t | log_builtins_stack_get_service_from_var (const char **s, const char **e, char *d) |
Helper: get token from error stack configuration string. More... | |
static my_h_service | log_service_get_by_name (const char *name, size_t len, char **urn) |
Look up a log service by name (in the service registry). More... | |
static log_service_cache_entry * | log_service_cache_entry_new (const char *name, size_t name_len, my_h_service srv, char *urn) |
Create a new entry in the cache of log services. More... | |
static int | log_service_get_characteristics (my_h_service service) |
Find out characteristics of a service (e.g. More... | |
log_service_instance * | log_service_instance_new (log_service_cache_entry *sce, log_line *ll) |
Allocate and open a new instance of a given service. More... | |
static void | log_service_instance_release_all () |
Close and release all instances of all log services. More... | |
int | log_builtins_error_stack_flush () |
Call flush() on all log_services. More... | |
log_error_stack_error | log_builtins_error_stack (const char *conf, bool check_only, size_t *pos) |
Set up custom error logging stack. More... | |
void | log_builtins_error_stack_wrlock () |
Acquire an exclusive lock on the error logger core. More... | |
void | log_builtins_error_stack_unlock () |
Release a lock on the error logger core. More... | |
int | log_builtins_exit () |
De-initialize the structured logging subsystem. More... | |
int | log_builtins_init () |
Initialize the structured logging subsystem. More... | |
log_service_error | make_log_path (char *result, const char *name_or_ext) |
Create a log-file name (path + name + extension). More... | |
log_service_error | log_close_errstream (void **my_errstream) |
Close an error log file previously opened with open_errstream(). More... | |
Variables | |
PSI_memory_key | key_memory_log_error_loaded_services |
PSI_memory_key | key_memory_log_error_stack |
log_line_processor | log_line_process_hook = log_line_buffer_event |
The function pointed to by this hook is run when a log-event is submitted. More... | |
static collation_unordered_map< string, cache_entry_with_deleter > * | log_service_cache |
static mysql_rwlock_t | THR_LOCK_log_stack |
Lock for the log "stack" (i.e. More... | |
static mysql_mutex_t | THR_LOCK_log_syseventlog |
Make sure only one instance of syslog/Eventlog code runs at a time. More... | |
static ulonglong | log_builtins_inited = 0 |
When the logger-core was initialized. More... | |
log_service_instance * | log_service_instances = nullptr |
Chain of log-service instances. More... | |
log_service_instance * | log_sink_pfs_source = nullptr |
The first configured writer that also has a log-reader is the source for the "data" field in performance_schema.error_log. More... | |
static enum log_error_stage | log_error_stage_current = LOG_ERROR_STAGE_BUFFERING |
What mode is error-logging in (e.g. are loadable services available yet)? More... | |
static const log_item_wellknown_key | log_item_wellknown_keys [] |
We support a number of predefined keys, such as "error-code" or "message". More... | |
static uint | log_item_wellknown_keys_count |
#define LOG_SERVICES_PREFIX "log_service" |
Name of the interface that log-services implements.
#define LOG_SERVICES_URN "file://component_" |
URN-prefix used to load a log-component.
When log-components passed to log_builtins_error_stack() are neither built-in nor have they been loaded already, this prefix will be prepended to their name to look them up using the component framework. Thus, "log_sink_json" will be looked up as "file://component_log_sink_json" and so on.
#define LOG_SUBSYSTEM_TAG "Server" |
using cache_entry_with_deleter = unique_ptr<log_service_cache_entry, log_service_cache_entry_free> |
We're caching handles to the services used in error logging as looking them up is costly.
typedef struct _log_item_wellknown_key log_item_wellknown_key |
Pre-defined "well-known" keys, as opposed to ad hoc ones, for key/value pairs in logging.
ulonglong iso8601_timestamp_to_microseconds | ( | 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_error_stack_error log_builtins_error_stack | ( | const char * | conf, |
bool | check_only, | ||
size_t * | pos | ||
) |
Set up custom error logging stack.
conf | The configuration string | |
check_only | If true, report on whether configuration is valid (i.e. whether all requested services are available), but do not apply the new configuration. if false, set the configuration (acquire the necessary services, update the hash by adding/deleting entries as necessary) | |
[out] | pos | If an error occurs and this pointer is non-null, the position in the configuration string where the error occurred will be written to the pointed-to size_t. |
LOG_ERROR_STACK_SUCCESS | success |
LOG_ERROR_STACK_DELIMITER_MISSING | expected delimiter not found |
LOG_ERROR_STACK_SERVICE_MISSING | one or more services not found |
LOG_ERROR_STACK_CACHE_ENTRY_OOM | couldn't create service cache entry |
LOG_ERROR_STACK_MULTITON_DENIED | tried to multi-open singleton |
LOG_ERROR_STACK_SERVICE_INSTANCE_OOM | couldn't create service instance entry |
LOG_ERROR_STACK_ENDS_IN_NON_SINK | last element should be a sink |
LOG_ERROR_STACK_SERVICE_UNAVAILABLE | service only available during start-up (may not be set by the user) |
LOG_ERROR_STACK_NO_PFS_SUPPORT | (check_only warning) no sink with performance_schema support selected |
LOG_ERROR_STACK_NO_LOG_PARSER | (check_only warning) no sink providing a log-parser selected |
LOG_ERROR_MULTIPLE_FILTERS | (check_only warning) more than one filter service selected |
LOG_ERROR_UNEXPECTED_DELIMITER_FOUND | service starts with a delimiter |
LOG_ERROR_MIXED_DELIMITERS | use ',' or ';', not both! |
int log_builtins_error_stack_flush | ( | ) |
Call flush() on all log_services.
flush() function must not try to log anything, as we hold an exclusive lock on the stack.
void log_builtins_error_stack_unlock | ( | ) |
Release a lock on the error logger core.
void log_builtins_error_stack_wrlock | ( | ) |
Acquire an exclusive lock on the error logger core.
Used e.g. to pause all logging while the previous run's log is read to performance_schema.error_log.
int log_builtins_exit | ( | ) |
De-initialize the structured logging subsystem.
0 | no errors |
-1 | not stopping, never started |
int log_builtins_init | ( | ) |
Initialize the structured logging subsystem.
Since we're initializing various locks here, we must call this late enough so this is clean, but early enough so it still happens while we're running single-threaded – this specifically also means we must call it before we start plug-ins / storage engines / external components!
0 | no errors |
-1 | couldn't initialize stack lock |
-2 | couldn't initialize built-in default filter |
-3 | couldn't set up service hash |
-4 | couldn't initialize syseventlog lock |
-5 | couldn't initialize buffered logging lock |
|
static |
Helper: get token from error stack configuration string.
[in,out] | s | start of the token (may be positioned on whitespace on call; this will be adjusted to the first non-white character) |
[out] | e | end of the token |
[in,out] | d | delimiter (in: last used, \0 if none; out: detected here) |
<0 | an error occurred |
>=0 | the length in bytes of the token |
ulonglong log_builtins_started | ( | ) |
When the logger-core was initialized.
0 | logger-core is not currently available |
>0 | time (micro-seconds since the epoch) the logger became available |
log_service_error log_close_errstream | ( | void ** | my_errstream | ) |
Close an error log file previously opened with open_errstream().
my_errstream | a handle describing the log file |
enum log_error_stage log_error_stage_get | ( | void | ) |
What mode is error-logging in (e.g. are loadable services available yet)?
void log_error_stage_set | ( | enum log_error_stage | les | ) |
Set error-logging stage hint (e.g. are loadable services available yet?).
void log_item_free | ( | log_item * | li | ) |
Release any of key and value on a log-item that were dynamically allocated.
li | log-item to release the payload of |
bool log_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 |
void log_item_get_float | ( | log_item * | li, |
double * | f | ||
) |
Get a float value from a log-item of float or integer type.
li | log item to get the value from |
f | float to store the value in |
Get an integer value from a log-item of float or integer type.
li | log item to get the value from |
i | longlong to store the value in |
void log_item_get_string | ( | log_item * | li, |
char ** | str, | ||
size_t * | len | ||
) |
Get a string value from a log-item of C-string or Lex string type.
li | log item to get the value from |
str | char-pointer to store the pointer to the value in |
len | size_t pointer to store the length of the value in |
int log_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) |
void log_item_init | ( | log_item * | li | ) |
Initializes a log entry for use.
This simply puts it in a defined state; if you wish to reset an existing item, see log_item_free().
li | the log-item to initialize |
bool log_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 * log_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 log_item_set_buffer | ( | log_item_data * | lid, |
char * | s, | ||
size_t | s_len | ||
) |
Set a string buffer on a log_item.
On success, the caller should change the item_class to LOG_BUFFER.
lid | log_item_data struct to set the value on |
s | pointer to string-buffer (non-const) |
s_len | buffer-size |
true | could not set a valid buffer |
false | item was assigned a buffer |
bool log_item_set_cstring | ( | log_item_data * | lid, |
const char * | s | ||
) |
Set a string value on a log_item.
Fails gracefully if not 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 log_item_set_float | ( | log_item_data * | lid, |
double | f | ||
) |
Set a floating point value on a log_item.
Fails gracefully if not 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 log_item_set_int | ( | log_item_data * | lid, |
longlong | i | ||
) |
Set an integer value on a log_item.
Fails gracefully if not 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 log_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 not 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 * log_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 log_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 |
int log_item_wellknown_by_name | ( | const char * | key, |
size_t | len | ||
) |
See whether a string is a wellknown field name.
key | potential key starts here |
len | 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 log_item_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 |
log_item_class log_item_wellknown_get_class | ( | uint | idx | ) |
Accessor: from a record describing a wellknown key, get its class.
idx | index in array of wellknowns, see log_item_wellknown_by_...() |
the | log item class for the wellknown key |
const char * log_item_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 log_item_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 |
const char * log_label_from_prio | ( | int | prio | ) |
Convenience function: Derive a log label ("error", "warning", "information") from a severity.
prio | the severity/prio in question |
ERROR | for prio of ERROR_LEVEL or higher |
Warning | for prio of WARNING_LEVEL |
Note | otherwise |
bool log_line_buffer_event | ( | log_line * | ll | ) |
Initial log-processor: Just buffer events until we have external log-components.
ll | the log-event to buffer |
true | log_sink_buffer() failed |
false | log_sink_buffer() succeeded |
bool log_line_error_stack_run | ( | log_line * | ll | ) |
MySQL server's default log-processor.
Apply all components (filters, sinks, ...) in the log stack to a given event.
ll | the log-event to process |
true | failure |
false | success |
void log_line_exit | ( | log_line * | ll | ) |
Release a log_line allocated with line_init()
Release a log_line allocated with log_line_init.
ll | a log_line previously allocated with line_init() |
bool log_line_full | ( | log_line * | ll | ) |
Predicate indicating whether a log line is "willing" to accept any more key/value pairs.
ll | the log-line to examine |
false | if not full / if able to accept another log_item |
true | if full |
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 |
Find the (index of the) first key/value pair of the given type in the log line.
This variant accepts a reference item and looks for an item that is of the same type (for wellknown types), or one that is of a generic type, and with the same key name (for generic types). For example, a reference item containing a generic string with key "foo" will a generic string, integer, or float with the key "foo".
ll | log line |
ref | a reference item of the log item type to look for |
<0 | none found |
>=0 | index of the key/value pair in the log line |
int log_line_index_by_name | ( | log_line * | ll, |
const char * | key | ||
) |
Find the (index of the) last key/value pair of the given name in the log line.
ll | log line |
key | the key to look for |
-1 | none found |
-2 | invalid search-key given |
-3 | no log_line given |
>=0 | index of the key/value pair in the log line |
int log_line_index_by_type | ( | log_line * | ll, |
log_item_type | t | ||
) |
Find the (index of the) first key/value pair of the given type in the log line.
ll | log line |
t | the log item type to look for |
<0 | none found |
>=0 | index of the key/value pair in the log line |
log_line * log_line_init | ( | ) |
Initialize a log_line.
nullptr | could not set up buffer (too small?) |
other | address of the newly initialized log_line |
Find the last item matching the given key in the log line.
ll | log line |
key | the key to look for |
nullptr | item not found |
otherwise | pointer to the item (not a copy thereof!) |
int log_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 |
void log_line_item_free | ( | log_line * | ll, |
size_t | elem | ||
) |
Release log line item (key/value pair) with the index elem in log line ll.
This frees whichever of key and value were dynamically allocated. This leaves a "gap" in the bag that may immediately be overwritten with an updated element. If the intention is to remove the item without replacing it, use log_line_item_remove() instead!
ll | log_line |
elem | index of the key/value pair to release |
void log_line_item_free_all | ( | log_line * | ll | ) |
Release all log line items (key/value pairs) in log line ll.
This frees whichever keys and values were dynamically allocated.
ll | log_line |
Initializes an entry in a log line for use.
This simply puts it in a defined state; if you wish to reset an existing item, see log_item_free(). This resets the element beyond the last. The element count is not adjusted; this is for the caller to do once it sets up a valid element to suit its needs in the cleared slot. Finally, it is up to the caller to make sure that an element can be allocated.
ll | the log-line to initialize a log_item in |
the | address of the cleared log_item |
void log_line_item_remove | ( | log_line * | ll, |
int | elem | ||
) |
Release log line item (key/value pair) with the index elem in log line ll.
This frees whichever of key and value were dynamically allocated. This moves any trailing items to fill the "gap" and decreases the counter of elements in the log line. If the intention is to leave a "gap" in the bag that may immediately be overwritten with an updated element, use log_line_item_free() instead!
ll | log_line |
elem | index of the key/value pair to release |
log_item_data * log_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.
It is up to the caller to ensure the log_line can accept more items (e.g. by using log_line_full(ll)).
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 * log_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).
It is up to the caller to ensure the log_line can accept more items (e.g. by using log_line_full(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.
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 log_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 |
log_line_processor log_line_process_hook_get | ( | void | ) |
Get current log-event processor.
When a log-event is submitted, a function is applied to that event. That function usually either buffers the event for later processing, or filters and logs the event. log_line_process_hook_get() returns a pointer to that function.
a | pointer to a log-event processing function |
void log_line_process_hook_set | ( | log_line_processor | llp | ) |
Set the log-event processor.
When a log-event is submitted, a function is applied to that event. That function usually either buffers the event for later processing, or filters and logs the event. That function can be set here.
llp | A log-processor |
int log_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.
ll | key/value pairs describing info to log |
int | number of fields in created log line |
enum loglevel log_prio_from_label | ( | const char * | label | ) |
Derive the event's priority (SYSTEM_LEVEL, ERROR_LEVEL, ...) from a textual label.
If the label can not be identified, default to ERROR_LEVEL as it is better to keep something that needn't be kept than to discard something that shouldn't be.
label | The prio label as a \0 terminated C-string. |
the | priority (as an enum loglevel) |
|
static |
Create a new entry in the cache of log services.
name | Name of component that provides the service |
name_len | Length of that name |
srv | The handle of the log_service |
urn | Pointer to allocated buffer containing an URN, or NULL |
A | new log_service_cache_entry on success |
nullptr | on failure |
|
static |
Test whether a given log-service name refers to a built-in service (built-in filter or built-in sink at this point).
name | the name – either just the component's, or a fully qualified service.component |
len | the length of the aforementioned name |
|
static |
Look up a log service by name (in the service registry).
name | name of the component | |
len | length of that name | |
[out] | urn | if the component was loaded implicitly, returns a pointer to a newly-allocated buffer containing the URN used |
a | handle to that service (or nullptr on failure) |
|
static |
Find out characteristics of a service (e.g.
whether it is a singleton) by asking it.
(See log_service_chistics for a list of possible characteristics!)
service | what service to examine |
a | set of log_service_chistics flags |
|
inlinestatic |
Test whether given service has all of the given characteristics.
(See log_service_chistics for a list!)
sce | service cache entry for the service in question |
required_flags | flags we're interested in (bitwise or'd) |
true | if all given flags are present, false otherwise |
log_service_instance * log_service_instance_new | ( | log_service_cache_entry * | sce, |
log_line * | ll | ||
) |
Allocate and open a new instance of a given service.
sce | the cache-entry for the service |
ll | a log_line containing optional parameters, or nullptr |
|
static |
Close and release all instances of all log services.
int log_string_compare | ( | const char * | a, |
const char * | b, | ||
size_t | len, | ||
bool | case_insensitive | ||
) |
Modular logger: log line and key/value manipulation helpers.
Server-internal. External services should access these via the log_builtins service API (cf. preamble for this file). Compare two NUL-terminated byte strings
Note that when comparing without length limit, the long string is greater if they're equal up to the length of the shorter string, but the shorter string will be considered greater if its "value" up to that point is greater:
compare 'abc','abcd': -100 (longer wins if otherwise same) compare 'abca','abcd': -3 (higher value wins) compare 'abcaaaaa','abcd': -3 (higher value wins)
a | the first string |
b | the second string |
len | compare at most this many characters – 0 for no limit |
case_insensitive | ignore upper/lower case in comparison |
-1 | a < b |
0 | a == b |
1 | a > b |
int make_iso8601_timestamp | ( | char * | buf, |
ulonglong | utime, | ||
enum enum_iso8601_tzmode | mode | ||
) |
Make and return an ISO 8601 / RFC 3339 compliant timestamp.
Accepts the log_timestamps global variable in its third parameter.
buf | A buffer of at least iso8601_size bytes to store the timestamp in. The timestamp will be \0 terminated. |
utime | Microseconds since the epoch |
mode | if 0, use UTC; if 1, use local time |
length | of timestamp (excluding \0) |
log_service_error make_log_path | ( | char * | result, |
const char * | name_or_ext | ||
) |
Create a log-file name (path + name + extension).
The path will be taken from @log_error. If name + extension are given, they are used. If only an extension is given (argument starts with '.'), the name is taken from @log_error, and the extension is used. If only a name is given (but no extension), the name and a default extension are used.
result | Buffer to return to created path+name+extension in. Size must be FN_REFLEN. |
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!
LOG_SERVICE_SUCCESS | buffer contains a valid result |
LOG_SERVICE_BUFFER_SIZE_INSUFFICIENT | an error occurred |
PSI_memory_key key_memory_log_error_loaded_services |
PSI_memory_key key_memory_log_error_stack |
|
static |
When the logger-core was initialized.
0: logger-core is not currently available >0: time (micro-seconds since the epoch) the logger-core became available
|
static |
What mode is error-logging in (e.g. are loadable services available yet)?
|
static |
We support a number of predefined keys, such as "error-code" or "message".
These are defined here. We also support user-defined "ad hoc" (or "generic") keys that let users of the error stack add values with arbitrary keys (as long as those keys don't coincide with the wellknown ones, anyway).
The idea here is that we want the flexibility of arbitrary keys, while being able to do certain optimizations for the common case. This also allows us to relatively cheaply add some convenience features, e.g. we know that error symbol ("ER_STARTUP") and error code (1451) are related, and can supply one as the other is submitted. Likewise of course, we can use the error code to fetch the associated registered error message string for that error code. Et cetera!
|
static |
log_line_processor log_line_process_hook = log_line_buffer_event |
The function pointed to by this hook is run when a log-event is submitted.
By default (until any sinks are set), we just buffer incoming events.
|
static |
log_service_instance* log_service_instances = nullptr |
Chain of log-service instances.
anchor
(Each service can have no/one/several instances.)
log_service_instance* log_sink_pfs_source = nullptr |
The first configured writer that also has a log-reader is the source for the "data" field in performance_schema.error_log.
log-reader
|
static |
Lock for the log "stack" (i.e.
the list of active log-services). X-locked while stack is changed/configured. S-locked while stack is used.
|
static |
Make sure only one instance of syslog/Eventlog code runs at a time.
(The loadable log-service is a singleton, which enforces that at most one instance of it exists. The logger-core has its own lock that serializes access to it. That however does not prevent the logger core and system variable updates from using Eventlog functions concurrently. This lock guards against that. It also serializes any other (non-error logging) users of this service.