182 ulonglong query_start_arg,
const char *user_host,
183 size_t user_host_len,
ulonglong query_utime,
185 const char *sql_text,
size_t sql_text_len) = 0;
216 const char *user_host,
size_t user_host_len,
218 size_t command_type_len,
const char *sql_text,
228 const char *user_host,
size_t user_host_len,
230 const char *sql_text,
size_t sql_text_len)
override;
235 const char *command_type,
size_t command_type_len,
236 const char *sql_text,
size_t sql_text_len,
354 const char *format, ...)
355 MY_ATTRIBUTE((format(printf, 4, 5)));
368 const
char *
query,
size_t query_length);
425 bool check_if_opened) const;
552 ulong prepare_summary(ulong rate);
562 summary_template(msg) {}
569 static const ulong LOG_THROTTLE_WINDOW_SIZE = 60000000;
627 void print_summary(
THD *thd, ulong suppressed,
ulonglong print_lock_time,
663 bool log(
THD *thd,
bool eligible);
684 (
unsigned long)suppressed);
698 const char *subsystem,
const char *msg)
743#define log_errlog(level, errcode, ...) \
744 log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
745 LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
746 (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, \
747 LOG_ITEM_LOG_LOOKUP, (longlong)errcode, ##__VA_ARGS__)
760#define log_errlog_formatted(level, ...) \
761 log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
762 LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
763 (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, \
764 LOG_ITEM_LOG_MESSAGE, ##__VA_ARGS__)
770#define log_errlog_rich(level, ...) \
771 log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
772 LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
773 (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, __VA_ARGS__)
785#define sql_print_information(...) \
786 log_errlog_formatted(INFORMATION_LEVEL, ##__VA_ARGS__)
788#define sql_print_warning(...) \
789 log_errlog_formatted(WARNING_LEVEL, ##__VA_ARGS__)
791#define sql_print_error(...) log_errlog_formatted(ERROR_LEVEL, ##__VA_ARGS__)
905 bool case_insensitive);
1560 bool check_only,
size_t *pos);
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
void print_summary(ulong suppressed)
Actually print the prepared summary to log.
Definition: log.h:680
const char * subsys
Definition: log.h:675
loglevel ll
Definition: log.h:673
Error_log_throttle(ulong window_usecs, loglevel lvl, uint errcode, const char *subsystem, const char *msg)
Definition: log.h:697
uint err_code
Definition: log.h:674
Abstract superclass for handling logging to slow/general logs.
Definition: log.h:159
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:493
bool in_window(ulonglong now) const
Check whether we're still in the current window.
Definition: log.h:540
const ulong window_size
Log no more than rate lines of a given type per window_size (e.g.
Definition: log.h:503
Log_throttle(ulong window_usecs, const char *msg)
Definition: log.h:558
bool inc_log_count(ulong rate)
Increase count of logs we're handling.
Definition: log.h:533
ulong count
There have been this many lines of this type in this window, including those that we suppressed.
Definition: log.h:511
ulonglong window_end
When will/did current window end?
Definition: log.h:497
const char * summary_template
Template for the summary line.
Definition: log.h:518
Class responsible for table based logging.
Definition: log.h:224
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:989
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:1161
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:863
Class responsible for file based logging.
Definition: log.cc:1197
Class which manages slow and general log event handlers.
Definition: log.h:261
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:1579
mysql_rwlock_t LOCK_logger
RW-lock protecting Query_logger.
Definition: log.h:273
Query_logger()
Definition: log.h:293
Log_event_handler * slow_log_handler_list[MAX_LOG_HANDLERS_NUM+1]
NULL-terminated arrays of log handlers.
Definition: log.h:280
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:1379
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:1555
bool activate_log_handler(THD *thd, enum_log_table_type log_type)
Activate log handlers for the given log type.
Definition: log.cc:1505
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:1296
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:1547
Log_to_file_event_handler * file_log_handler
Definition: log.h:277
bool general_log_print(THD *thd, enum_server_command command, const char *format,...)
Write printf style message to general query log.
Definition: log.cc:1415
void cleanup()
Free memory.
Definition: log.cc:1287
void deactivate_log_handler(enum_log_table_type log_type)
Close file log for the given log type.
Definition: log.cc:1518
Log_event_handler * general_log_handler_list[MAX_LOG_HANDLERS_NUM+1]
Definition: log.h:281
Log_to_csv_event_handler table_log_handler
Available log handlers.
Definition: log.h:276
void set_handlers(ulonglong log_printer)
Enable log event handlers for slow/general log.
Definition: log.cc:1496
bool set_log_file(enum_log_table_type log_type)
Read log file name from global variable opt_*_logname.
Definition: log.cc:1525
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:1273
static const uint MAX_LOG_HANDLERS_NUM
Currently we have only 2 kinds of logging functions: old-fashioned file logs and csv logging routines...
Definition: log.h:266
void init()
Perform basic log initialization: create file-based log handler.
Definition: log.cc:1282
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:1448
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:581
log_summary_t log_summary
The routine we call to actually log a line (our summary).
Definition: log.h:612
mysql_mutex_t * LOCK_log_throttle
Slow_log_throttle is shared between THDs.
Definition: log.h:617
ulong * rate
A reference to the threshold ("no more than n log lines per ...").
Definition: log.h:607
Security_context aggregate_sctx
We're using our own (empty) security context during summary generation.
Definition: log.h:589
ulonglong total_lock_time
Total of the lock times of queries in this time-window for which we suppressed logging.
Definition: log.h:601
ulonglong total_exec_time
Total of the execution times of queries in this time-window for which we suppressed logging.
Definition: log.h:595
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:462
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:345
bool(* log_summary_t)(THD *thd, const char *query, size_t query_length, bool aggregate, ulonglong lock_usec, ulonglong exec_usec)
Definition: log.h:572
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:568
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:2008
char * make_query_log_name(char *buff, enum_log_table_type log_type)
Create the name of the query log specified.
Definition: log.cc:1585
enum_iso8601_tzmode
Whether to generate a UTC timestamp, or one following system-time.
Definition: log.h:1430
@ iso8601_utc
create UTC timestamp
Definition: log.h:1432
@ iso8601_sysvar_logtimestamps
use value of opt_log_timestamps
Definition: log.h:1431
@ iso8601_system_time
use system time
Definition: log.h:1433
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:962
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:1645
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:373
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:760
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:866
void log_write_errstream(const char *buffer, size_t length)
Interim helper: write to the default error stream.
Definition: log.cc:1991
bool init_error_log()
Initialize structures (e.g.
Definition: log.cc:1872
Query_logger query_logger
Definition: log.cc:1583
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:664
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:841
bool log_item_set_float(log_item_data *lid, double f)
Set a floating point value on a log_item.
Definition: log_builtins.cc:928
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:1007
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:388
void destroy_error_log()
Free any error log resources.
Definition: log.cc:1939
log_item * log_line_item_init(log_line *ll)
Initializes an entry in a log line for use.
Definition: log_builtins.cc:801
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:401
log_line * log_line_init()
Initialize a log_line.
Definition: log_builtins.cc:583
int log_line_submit(log_line *ll)
Complete, filter, and write submitted log items.
Definition: log_builtins.cc:1117
static const uint LOG_FILE
Definition: log.h:255
void log_item_init(log_item *li)
Initializes a log entry for use.
Definition: log_builtins.cc:786
bool reopen_error_log()
Flush any pending data to disk and reopen the error log.
Definition: log.cc:1951
void log_slow_statement(THD *thd)
Check whether we need to write the current statement to the slow query log.
Definition: log.cc:1668
void log_line_exit(log_line *ll)
Release a log_line allocated with log_line_init.
Definition: log_builtins.cc:596
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:405
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:1837
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:503
enum_log_error_stack_error
Well-known values returned by log_error_stack().
Definition: log.h:1466
@ LOG_ERROR_STACK_SERVICE_MISSING
one or more services not found
Definition: log.h:1474
@ LOG_ERROR_STACK_NO_PFS_SUPPORT
check-only warning: no sink supporting pfs given
Definition: log.h:1492
@ LOG_ERROR_STACK_SERVICE_INSTANCE_OOM
couldn't create service instance entry
Definition: log.h:1483
@ LOG_ERROR_STACK_MULTITON_DENIED
tried to multi-open singleton
Definition: log.h:1480
@ LOG_ERROR_STACK_CACHE_ENTRY_OOM
couldn't create service cache entry
Definition: log.h:1477
@ LOG_ERROR_STACK_SUCCESS
success
Definition: log.h:1468
@ LOG_ERROR_MULTIPLE_FILTERS
check-only warning: more than one log-filter given
Definition: log.h:1498
@ LOG_ERROR_STACK_ENDS_IN_NON_SINK
last element in pipeline should be a sink
Definition: log.h:1486
@ LOG_ERROR_UNEXPECTED_DELIMITER_FOUND
service name may not start with a delimiter
Definition: log.h:1501
@ LOG_ERROR_STACK_DELIMITER_MISSING
expected delimiter not found
Definition: log.h:1471
@ LOG_ERROR_STACK_NO_LOG_PARSER
check-only warning: no log-parser given
Definition: log.h:1495
@ LOG_ERROR_STACK_SERVICE_UNAVAILABLE
service only available during start-up (may not be set by the user)
Definition: log.h:1489
@ LOG_ERROR_MIXED_DELIMITERS
delimiters ',' and ';' may not be mixed
Definition: log.h:1504
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:413
int log_message(int log_type,...)
Variadic convenience function for logging.
Definition: log.cc:2319
static const uint LOG_NONE
Definition: log.h:254
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:627
int log_line_item_count(log_line *ll)
How many items are currently set on the given log_line?
Definition: log_builtins.cc:638
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:747
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:1599
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:916
int log_builtins_init()
Initialize the structured logging subsystem.
Definition: log_builtins.cc:2200
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:691
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:715
enum_log_table_type
Type of the log table.
Definition: log.h:149
@ QUERY_LOG_NONE
Definition: log.h:150
@ QUERY_LOG_GENERAL
Definition: log.h:152
@ QUERY_LOG_SLOW
Definition: log.h:151
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:492
void error_log_print(enum loglevel level, uint ecode, va_list args)
Prints a printf style message to the error log.
Definition: log.cc:2296
const char * log_item_wellknown_get_name(uint idx)
Accessor: from a record describing a wellknown key, get its name.
Definition: log_builtins.cc:481
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:912
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:2053
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:649
int make_iso8601_timestamp(char *buf, ulonglong utime, enum enum_iso8601_tzmode mode)
Make and return an ISO 8601 / RFC 3339 compliant timestamp.
Definition: log_builtins.cc:1351
int log_builtins_exit()
De-initialize the structured logging subsystem.
Definition: log_builtins.cc:2166
int log_builtins_error_stack_flush()
Call flush() on all log_services.
Definition: log_builtins.cc:1718
bool log_item_set_cstring(log_item_data *lid, const char *s)
Set a string value on a log_item.
Definition: log_builtins.cc:971
bool is_valid_log_name(const char *name, size_t len)
Check given log name against certain blacklisted names/extensions.
Definition: log.cc:399
void discard_error_log_messages()
Discard all buffered messages and deallocate buffer without printing anything.
Definition: log.cc:1864
bool log_item_set_int(log_item_data *lid, longlong i)
Set an integer value on a log_item.
Definition: log_builtins.cc:920
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:1868
const char * log_label_from_prio(int prio)
Convenience function: Derive a log label ("error", "warning", "information") from a severity.
Definition: log_builtins.cc:980
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:742
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:420
log_item * log_line_get_output_buffer(log_line *ll)
Get log-line's output buffer.
Definition: log_builtins.cc:612
static const uint LOG_TABLE
Definition: log.h:256
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:1421
bool open_error_log(const char *filename, bool get_lock)
Open the error log and redirect stderr and optionally stdout to the error log file.
Definition: log.cc:1889
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:675
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:439
#define window_size
Definition: log_event.cc:175
enum enum_log_item_class log_item_class
@ LOG_TYPE_ERROR
Definition: log_shared.h:68
@ LOG_ITEM_LOG_MESSAGE
the message, format string
Definition: log_shared.h:145
@ LOG_ITEM_LOG_PRIO
log priority (error, warn, ...)
Definition: log_shared.h:142
@ LOG_ITEM_SRV_SUBSYS
log called from subsystem ...
Definition: log_shared.h:135
@ LOG_ITEM_SQL_ERRCODE
mysql error code (numeric)
Definition: log_shared.h:127
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:216
static int log_type
Definition: mi_log.cc:47
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:63
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:1081
Definition: buf0block_hint.cc:30
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
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
mode
Definition: file_handle.h:61
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:196
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:185
command
Definition: version_token.cc:280