183 ulonglong query_start_arg,
const char *user_host,
184 size_t user_host_len,
ulonglong query_utime,
186 const char *sql_text,
size_t sql_text_len) = 0;
217 const char *user_host,
size_t user_host_len,
219 size_t command_type_len,
const char *sql_text,
229 const char *user_host,
size_t user_host_len,
231 const char *sql_text,
size_t sql_text_len)
override;
236 const char *command_type,
size_t command_type_len,
237 const char *sql_text,
size_t sql_text_len,
260class Log_to_telemetry_event_handler;
360 MY_ATTRIBUTE((
format(printf, 4, 5)));
373 const
char *
query,
size_t query_length);
430 bool check_if_opened) const;
557 ulong prepare_summary(ulong rate);
567 summary_template(msg) {}
574 static const ulong LOG_THROTTLE_WINDOW_SIZE = 60000000;
632 void print_summary(
THD *thd, ulong suppressed,
ulonglong print_lock_time,
668 bool log(
THD *thd,
bool eligible);
689 (
unsigned long)suppressed);
703 const char *subsystem,
const char *msg)
748#define log_errlog(level, errcode, ...) \
749 log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
750 LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
751 (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, \
752 LOG_ITEM_LOG_LOOKUP, (longlong)errcode, ##__VA_ARGS__)
765#define log_errlog_formatted(level, ...) \
766 log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
767 LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
768 (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, \
769 LOG_ITEM_LOG_MESSAGE, ##__VA_ARGS__)
775#define log_errlog_rich(level, ...) \
776 log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
777 LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
778 (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, __VA_ARGS__)
790#define sql_print_information(...) \
791 log_errlog_formatted(INFORMATION_LEVEL, ##__VA_ARGS__)
793#define sql_print_warning(...) \
794 log_errlog_formatted(WARNING_LEVEL, ##__VA_ARGS__)
796#define sql_print_error(...) log_errlog_formatted(ERROR_LEVEL, ##__VA_ARGS__)
911 bool case_insensitive);
1556 bool check_only,
size_t *pos);
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
void print_summary(ulong suppressed)
Actually print the prepared summary to log.
Definition: log.h:685
const char * subsys
Definition: log.h:680
loglevel ll
Definition: log.h:678
Error_log_throttle(ulong window_usecs, loglevel lvl, uint errcode, const char *subsystem, const char *msg)
Definition: log.h:702
uint err_code
Definition: log.h:679
Abstract superclass for handling logging to slow/general logs.
Definition: log.h:160
virtual bool log_slow(THD *thd, ulonglong current_utime, ulonglong query_start_arg, const char *user_host, size_t user_host_len, ulonglong query_utime, ulonglong lock_utime, bool is_command, const char *sql_text, size_t sql_text_len)=0
Log a query to the slow log.
virtual ~Log_event_handler()=default
virtual bool log_general(THD *thd, ulonglong event_utime, const char *user_host, size_t user_host_len, my_thread_id thread_id, const char *command_type, size_t command_type_len, const char *sql_text, size_t sql_text_len, const CHARSET_INFO *client_cs)=0
Log command to the general log.
Log_event_handler()=default
Base class for rate-limiting a log (slow query log etc.)
Definition: log.h:498
bool in_window(ulonglong now) const
Check whether we're still in the current window.
Definition: log.h:545
const ulong window_size
Log no more than rate lines of a given type per window_size (e.g.
Definition: log.h:508
Log_throttle(ulong window_usecs, const char *msg)
Definition: log.h:563
bool inc_log_count(ulong rate)
Increase count of logs we're handling.
Definition: log.h:538
ulong count
There have been this many lines of this type in this window, including those that we suppressed.
Definition: log.h:516
ulonglong window_end
When will/did current window end?
Definition: log.h:502
const char * summary_template
Template for the summary line.
Definition: log.h:523
Class responsible for table based logging.
Definition: log.h:225
bool log_slow(THD *thd, ulonglong current_utime, ulonglong query_start_arg, const char *user_host, size_t user_host_len, ulonglong query_utime, ulonglong lock_utime, bool is_command, const char *sql_text, size_t sql_text_len) override
Definition: log.cc:999
bool activate_log(THD *thd, enum_log_table_type log_type)
Check if log table for given log type exists and can be opened.
Definition: log.cc:1171
bool log_general(THD *thd, ulonglong event_utime, const char *user_host, size_t user_host_len, my_thread_id thread_id, const char *command_type, size_t command_type_len, const char *sql_text, size_t sql_text_len, const CHARSET_INFO *client_cs) override
Definition: log.cc:873
Class responsible for file based logging.
Definition: log.cc:1207
Class which manages slow and general log event handlers.
Definition: log.h:263
bool is_log_file_enabled(enum_log_table_type log_type) const
Check if file logging is turned on for the given log type.
Definition: log.cc:1769
mysql_rwlock_t LOCK_logger
RW-lock protecting Query_logger.
Definition: log.h:277
Query_logger()
Definition: log.h:298
Log_event_handler * slow_log_handler_list[MAX_LOG_HANDLERS_NUM+1]
NULL-terminated arrays of log handlers.
Definition: log.h:285
bool general_log_write(THD *thd, enum_server_command command, const char *query, size_t query_length)
Write query to general query log.
Definition: log.cc:1552
enum_log_table_type check_if_log_table(Table_ref *table_list, bool check_if_opened) const
Check if given Table_ref has a query log table name and optionally check if the query log is currentl...
Definition: log.cc:1745
bool activate_log_handler(THD *thd, enum_log_table_type log_type)
Activate log handlers for the given log type.
Definition: log.cc:1695
bool slow_log_write(THD *thd, const char *query, size_t query_length, bool aggregate, ulonglong lock_usec, ulonglong exec_usec)
Log slow query with all enabled log event handlers.
Definition: log.cc:1457
bool reopen_log_file(enum_log_table_type log_type)
Close file log for the given log type and the reopen it.
Definition: log.cc:1737
Log_to_file_event_handler * file_log_handler
Definition: log.h:281
bool general_log_print(THD *thd, enum_server_command command, const char *format,...)
Write printf style message to general query log.
Definition: log.cc:1602
void cleanup()
Free memory.
Definition: log.cc:1448
void deactivate_log_handler(enum_log_table_type log_type)
Close file log for the given log type.
Definition: log.cc:1708
Log_event_handler * general_log_handler_list[MAX_LOG_HANDLERS_NUM+1]
Definition: log.h:286
Log_to_csv_event_handler table_log_handler
Available log handlers.
Definition: log.h:280
void set_handlers(ulonglong log_printer)
Enable log event handlers for slow/general log.
Definition: log.cc:1686
Log_to_telemetry_event_handler * telemetry_log_handler
Definition: log.h:282
bool set_log_file(enum_log_table_type log_type)
Read log file name from global variable opt_*_logname.
Definition: log.cc:1715
bool is_log_table_enabled(enum_log_table_type log_type) const
Check if table logging is turned on for the given log_type.
Definition: log.cc:1434
static const uint MAX_LOG_HANDLERS_NUM
Currently we have 2 main kinds of logging functions: old-fashioned file logs and csv logging routines...
Definition: log.h:270
void init()
Perform basic log initialization: create file-based log handler.
Definition: log.cc:1443
void init_query_log(enum_log_table_type log_type, ulonglong log_printer)
Setup log event handlers for the given log_type.
Definition: log.cc:1638
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:54
Used for rate-limiting the slow query log.
Definition: log.h:586
log_summary_t log_summary
The routine we call to actually log a line (our summary).
Definition: log.h:617
mysql_mutex_t * LOCK_log_throttle
Slow_log_throttle is shared between THDs.
Definition: log.h:622
ulong * rate
A reference to the threshold ("no more than n log lines per ...").
Definition: log.h:612
Security_context aggregate_sctx
We're using our own (empty) security context during summary generation.
Definition: log.h:594
ulonglong total_lock_time
Total of the lock times of queries in this time-window for which we suppressed logging.
Definition: log.h:606
ulonglong total_exec_time
Total of the execution times of queries in this time-window for which we suppressed logging.
Definition: log.h:600
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
int log_item_wellknown_by_type(log_item_type t)
See whether a type is wellknown.
Definition: log_builtins.cc:486
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.
Definition: log_builtins.cc:369
bool(* log_summary_t)(THD *thd, const char *query, size_t query_length, bool aggregate, ulonglong lock_usec, ulonglong exec_usec)
Definition: log.h:577
void log_item_free(log_item *li)
Release any of key and value on a log-item that were dynamically allocated.
Definition: log_builtins.cc:592
my_thread_id log_get_thread_id(THD *thd)
A helper that we can stubify so we don't have to pull all of THD into the unit tests.
Definition: log.cc:2226
char * make_query_log_name(char *buff, enum_log_table_type log_type)
Create the name of the query log specified.
Definition: log.cc:1775
bool log_item_set_lexstring(log_item_data *lid, const char *s, size_t s_len)
Set a string value on a log_item.
Definition: log_builtins.cc:988
void log_slow_do(THD *thd)
Unconditionally writes the current statement (or its rewritten version if it exists) to the slow quer...
Definition: log.cc:1837
bool log_item_generic_type(log_item_type t)
Predicate used to determine whether a type is generic (generic string, generic float,...
Definition: log_builtins.cc:397
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.
Definition: log_builtins.cc:786
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_...
Definition: log_builtins.cc:892
bool init_error_log()
Initialize structures (e.g.
Definition: log.cc:2067
Query_logger query_logger
Definition: log.cc:1773
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.
Definition: log_builtins.cc:690
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).
Definition: log_builtins.cc:867
bool log_item_set_float(log_item_data *lid, double f)
Set a floating point value on a log_item.
Definition: log_builtins.cc:954
enum loglevel log_prio_from_label(const char *label)
Derive the event's priority (SYSTEM_LEVEL, ERROR_LEVEL, ...) from a textual label.
Definition: log_builtins.cc:1033
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).
Definition: log_builtins.cc:412
void destroy_error_log()
Free any error log resources.
Definition: log.cc:2142
log_item * log_line_item_init(log_line *ll)
Initializes an entry in a log line for use.
Definition: log_builtins.cc:827
enum enum_log_error_stack_error log_error_stack_error
Well-known values returned by log_error_stack().
bool log_item_numeric_class(log_item_class c)
Predicate used to determine whether a class is a numeric class (integer or float).
Definition: log_builtins.cc:425
log_line * log_line_init()
Initialize a log_line.
Definition: log_builtins.cc:607
int log_line_submit(log_line *ll)
Complete, filter, and write submitted log items.
Definition: log_builtins.cc:1172
static const uint LOG_FILE
Definition: log.h:256
void log_line_set_flag(log_line *ll, log_line_flags_mask mask, log_line_flags_mask value)
Set/reset one or more log line flags.
Definition: log_builtins.cc:1150
void log_item_init(log_item *li)
Initializes a log entry for use.
Definition: log_builtins.cc:812
bool reopen_error_log()
Flush any pending data to disk and reopen the error log.
Definition: log.cc:2197
void log_slow_statement(THD *thd)
Check whether we need to write the current statement to the slow query log.
Definition: log.cc:1860
void log_line_exit(log_line *ll)
Release a log_line allocated with log_line_init.
Definition: log_builtins.cc:622
void log_item_get_int(log_item *li, longlong *i)
Get an integer value from a log-item of float or integer type.
Definition: log_builtins.cc:429
log_error_stack_error log_builtins_error_stack(const char *conf, bool check_only, size_t *pos)
Set up custom error logging stack.
Definition: log_builtins.cc:1881
void log_write_errstream(const char *buffer, size_t length, enum enum_log_type log_type)
Interim helper: write to the default error stream.
Definition: log.cc:2205
log_item_class log_item_wellknown_get_class(uint idx)
Accessor: from a record describing a wellknown key, get its class.
Definition: log_builtins.cc:527
enum_log_error_stack_error
Well-known values returned by log_error_stack().
Definition: log.h:1462
@ LOG_ERROR_STACK_SERVICE_MISSING
one or more services not found
Definition: log.h:1470
@ LOG_ERROR_STACK_NO_PFS_SUPPORT
check-only warning: no sink supporting pfs given
Definition: log.h:1488
@ LOG_ERROR_STACK_SERVICE_INSTANCE_OOM
couldn't create service instance entry
Definition: log.h:1479
@ LOG_ERROR_STACK_MULTITON_DENIED
tried to multi-open singleton
Definition: log.h:1476
@ LOG_ERROR_STACK_CACHE_ENTRY_OOM
couldn't create service cache entry
Definition: log.h:1473
@ LOG_ERROR_STACK_SUCCESS
success
Definition: log.h:1464
@ LOG_ERROR_MULTIPLE_FILTERS
check-only warning: more than one log-filter given
Definition: log.h:1494
@ LOG_ERROR_STACK_ENDS_IN_NON_SINK
last element in pipeline should be a sink
Definition: log.h:1482
@ LOG_ERROR_UNEXPECTED_DELIMITER_FOUND
service name may not start with a delimiter
Definition: log.h:1497
@ LOG_ERROR_STACK_DELIMITER_MISSING
expected delimiter not found
Definition: log.h:1467
@ LOG_ERROR_STACK_NO_LOG_PARSER
check-only warning: no log-parser given
Definition: log.h:1491
@ LOG_ERROR_STACK_SERVICE_UNAVAILABLE
service only available during start-up (may not be set by the user)
Definition: log.h:1485
@ LOG_ERROR_MIXED_DELIMITERS
delimiters ',' and ';' may not be mixed
Definition: log.h:1500
void log_item_get_float(log_item *li, double *f)
Get a float value from a log-item of float or integer type.
Definition: log_builtins.cc:437
int log_message(int log_type,...)
Variadic convenience function for logging.
Definition: log.cc:2538
static const uint LOG_NONE
Definition: log.h:255
bool log_line_full(log_line *ll)
Predicate indicating whether a log line is "willing" to accept any more key/value pairs.
Definition: log_builtins.cc:653
int log_line_item_count(log_line *ll)
How many items are currently set on the given log_line?
Definition: log_builtins.cc:664
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.
Definition: log_builtins.cc:773
bool log_slow_applicable(THD *thd)
Check whether we need to write the current statement (or its rewritten version if it exists) to the s...
Definition: log.cc:1789
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".
Definition: log_builtins.cc:942
int log_builtins_init()
Initialize the structured logging subsystem.
Definition: log_builtins.cc:2244
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.
Definition: log_builtins.cc:717
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.
Definition: log_builtins.cc:741
enum_log_table_type
Type of the log table.
Definition: log.h:150
@ QUERY_LOG_NONE
Definition: log.h:151
@ QUERY_LOG_GENERAL
Definition: log.h:153
@ QUERY_LOG_SLOW
Definition: log.h:152
log_item_type log_item_wellknown_get_type(uint idx)
Accessor: from a record describing a wellknown key, get its type.
Definition: log_builtins.cc:516
void error_log_print(enum loglevel level, uint ecode, va_list args)
Prints a printf style message to the error log.
Definition: log.cc:2515
bool open_error_log(const char *filename, bool get_lock, uint log_type)
Open the error log and redirect stderr and optionally stdout to the error log file.
Definition: log.cc:2085
const char * log_item_wellknown_get_name(uint idx)
Accessor: from a record describing a wellknown key, get its name.
Definition: log_builtins.cc:505
Slow_log_throttle log_throttle_qni
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_...
Definition: log_builtins.cc:938
int log_vmessage(int log_type, va_list lili)
Write a message to a log (for now just used for error log).
Definition: log.cc:2271
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.
Definition: log_builtins.cc:675
int log_builtins_exit()
De-initialize the structured logging subsystem.
Definition: log_builtins.cc:2210
int log_builtins_error_stack_flush()
Call flush() on all log_services.
Definition: log_builtins.cc:1762
bool log_item_set_cstring(log_item_data *lid, const char *s)
Set a string value on a log_item.
Definition: log_builtins.cc:997
bool is_valid_log_name(const char *name, size_t len)
Check given log name against certain blacklisted names/extensions.
Definition: log.cc:405
void discard_error_log_messages()
Discard all buffered messages and deallocate buffer without printing anything.
Definition: log.cc:2059
bool log_item_set_int(log_item_data *lid, longlong i)
Set an integer value on a log_item.
Definition: log_builtins.cc:946
void flush_error_log_messages()
We buffer all error log messages that have been printed before the error log has been opened.
Definition: log.cc:2063
const char * log_label_from_prio(int prio)
Convenience function: Derive a log label ("error", "warning", "information") from a severity.
Definition: log_builtins.cc:1006
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.
Definition: log_builtins.cc:768
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.
Definition: log_builtins.cc:444
log_item * log_line_get_output_buffer(log_line *ll)
Get log-line's output buffer.
Definition: log_builtins.cc:638
static const uint LOG_TABLE
Definition: log.h:257
ulonglong iso8601_timestamp_to_microseconds(const char *timestamp, size_t len)
Parse a ISO8601 timestamp and return the number of microseconds since the epoch.
Definition: log_builtins.cc:1465
void log_line_item_free_all(log_line *ll)
Release all log line items (key/value pairs) in log line ll.
Definition: log_builtins.cc:701
int log_item_wellknown_by_name(const char *key, size_t len)
See whether a string is a wellknown field name.
Definition: log_builtins.cc:463
#define window_size
Definition: log_event.cc:177
uint64 log_line_flags_mask
a bit mask with flags describing a log line
Definition: log_shared.h:231
enum enum_log_item_class log_item_class
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:66
@ LOG_TYPE_ERROR
Definition: log_shared.h:68
@ LOG_ITEM_LOG_MESSAGE
the message, format string
Definition: log_shared.h:146
@ LOG_ITEM_LOG_PRIO
log priority (error, warn, ...)
Definition: log_shared.h:143
@ LOG_ITEM_SRV_SUBSYS
log called from subsystem ...
Definition: log_shared.h:136
@ LOG_ITEM_SQL_ERRCODE
mysql error code (numeric)
Definition: log_shared.h:128
enum enum_log_item_type log_item_type
item_type – what to log
uint64 log_item_type_mask
a bit mask of log_types.
Definition: log_shared.h:222
static int log_type
Definition: mi_log.cc:47
static mi_bit_type mask[]
Definition: mi_packrec.cc:141
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:48
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
long long int longlong
Definition: my_inttypes.h:55
uint32_t uint32
Definition: my_inttypes.h:67
Common #defines and includes for file and socket I/O.
Definition of the global "loglevel" enumeration.
loglevel
Definition: my_loglevel.h:41
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
static my_thread_id thread_id
Definition: my_thr_init.cc:60
uint32 my_thread_id
Definition: my_thread_local.h:34
static int count
Definition: myisam_ftdump.cc:45
static char * query
Definition: myisam_ftdump.cc:47
Common definition between mysql server & client.
ABI for instrumented mutexes.
Instrumentation helpers for rwlock.
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
constexpr value_type timestamp
Definition: classic_protocol_constants.h:278
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
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:76
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
static mysql_service_status_t flush(reference_caching_cache cache) noexcept
Definition: component.cc:114
static Logger logger
The "top-level" logger used when no connection context is given.
Definition: test_trace_plugin.cc:296
const char * filename
Definition: pfs_example_component_population.cc:67
Instrumentation helpers for mutexes.
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421
Definition: log_shared.h:202
log_line ("log event")
Definition: keyring_log_builtins_definition.cc:72
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:51
Definition: log_shared.h:191