MySQL 8.4.2
Source Code Documentation
Query_logger Class Reference

Class which manages slow and general log event handlers. More...

#include <log.h>

Public Member Functions

 Query_logger ()
 
bool is_log_table_enabled (enum_log_table_type log_type) const
 Check if table logging is turned on for the given log_type. More...
 
bool is_log_file_enabled (enum_log_table_type log_type) const
 Check if file logging is turned on for the given log type. More...
 
void init ()
 Perform basic log initialization: create file-based log handler. More...
 
void cleanup ()
 Free memory. More...
 
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. More...
 
bool general_log_print (THD *thd, enum_server_command command, const char *format,...)
 Write printf style message to general query log. More...
 
bool general_log_write (THD *thd, enum_server_command command, const char *query, size_t query_length)
 Write query to general query log. More...
 
void set_handlers (ulonglong log_printer)
 Enable log event handlers for slow/general log. More...
 
bool activate_log_handler (THD *thd, enum_log_table_type log_type)
 Activate log handlers for the given log type. More...
 
void deactivate_log_handler (enum_log_table_type log_type)
 Close file log for the given log type. More...
 
bool reopen_log_file (enum_log_table_type log_type)
 Close file log for the given log type and the reopen it. More...
 
bool set_log_file (enum_log_table_type log_type)
 Read log file name from global variable opt_*_logname. More...
 
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 currently enabled. More...
 

Private Member Functions

void init_query_log (enum_log_table_type log_type, ulonglong log_printer)
 Setup log event handlers for the given log_type. More...
 

Private Attributes

mysql_rwlock_t LOCK_logger
 RW-lock protecting Query_logger. More...
 
Log_to_csv_event_handler table_log_handler
 Available log handlers. More...
 
Log_to_file_event_handlerfile_log_handler
 
Log_event_handlerslow_log_handler_list [MAX_LOG_HANDLERS_NUM+1]
 NULL-terminated arrays of log handlers. More...
 
Log_event_handlergeneral_log_handler_list [MAX_LOG_HANDLERS_NUM+1]
 

Static Private Attributes

static const uint MAX_LOG_HANDLERS_NUM = 2
 Currently we have only 2 kinds of logging functions: old-fashioned file logs and csv logging routines. More...
 

Detailed Description

Class which manages slow and general log event handlers.

Constructor & Destructor Documentation

◆ Query_logger()

Query_logger::Query_logger ( )
inline

Member Function Documentation

◆ activate_log_handler()

bool Query_logger::activate_log_handler ( THD thd,
enum_log_table_type  log_type 
)

Activate log handlers for the given log type.

Parameters
thdThread handle
log_typeQUERY_LOG_SLOW or QUERY_LOG_GENERAL
Returns
true if error, false otherwise.

◆ check_if_log_table()

enum_log_table_type Query_logger::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 currently enabled.

Parameters
table_listTable_ref representing the table to check
check_if_openedAlways return QUERY_LOG_NONE unless the query log table is enabled.
Return values
QUERY_LOG_NONE,QUERY_LOG_SLOWor QUERY_LOG_GENERAL

◆ cleanup()

void Query_logger::cleanup ( )

Free memory.

Nothing could be logged after this function is called.

◆ deactivate_log_handler()

void Query_logger::deactivate_log_handler ( enum_log_table_type  log_type)

Close file log for the given log type.

Parameters
log_typeQUERY_LOG_SLOW or QUERY_LOG_GENERAL

◆ general_log_print()

bool Query_logger::general_log_print ( THD thd,
enum_server_command  command,
const char *  format,
  ... 
)

Write printf style message to general query log.

Parameters
thdTHD of the statement being logged.
commandCOM of statement being logged.
formatPrintf style format of message.
...Printf parameters to write.
Returns
true if error, false otherwise.

◆ general_log_write()

bool Query_logger::general_log_write ( THD thd,
enum_server_command  command,
const char *  query,
size_t  query_length 
)

Write query to general query log.

Parameters
thdTHD of the statement being logged.
commandCOM of statement being logged.
queryThe query string being logged.
query_lengthThe length of the query string.
Returns
true if error, false otherwise.

◆ init()

void Query_logger::init ( )

Perform basic log initialization: create file-based log handler.

We want to initialize all log mutexes as soon as possible, but we cannot do it in constructor, as safe_mutex relies on initialization, performed by MY_INIT(). This why this is done in this function.

◆ init_query_log()

void Query_logger::init_query_log ( enum_log_table_type  log_type,
ulonglong  log_printer 
)
private

Setup log event handlers for the given log_type.

Parameters
log_typeQUERY_LOG_SLOW or QUERY_LOG_GENERAL
log_printerBitmap of LOG_NONE, LOG_FILE, LOG_TABLE

◆ is_log_file_enabled()

bool Query_logger::is_log_file_enabled ( enum_log_table_type  log_type) const

Check if file logging is turned on for the given log type.

Parameters
log_typeQUERY_LOG_SLOW or QUERY_LOG_GENERAL
Returns
true if the file logging is on, false otherwise.

◆ is_log_table_enabled()

bool Query_logger::is_log_table_enabled ( enum_log_table_type  log_type) const

Check if table logging is turned on for the given log_type.

Parameters
log_typeQUERY_LOG_SLOW or QUERY_LOG_GENERAL
Returns
true if table logging is on, false otherwise.

◆ reopen_log_file()

bool Query_logger::reopen_log_file ( enum_log_table_type  log_type)

Close file log for the given log type and the reopen it.

Parameters
log_typeQUERY_LOG_SLOW or QUERY_LOG_GENERAL

◆ set_handlers()

void Query_logger::set_handlers ( ulonglong  log_printer)

Enable log event handlers for slow/general log.

Parameters
log_printerBitmask of log event handlers.
Note
Acceptable values are LOG_NONE, LOG_FILE, LOG_TABLE

◆ set_log_file()

bool Query_logger::set_log_file ( enum_log_table_type  log_type)

Read log file name from global variable opt_*_logname.

If called from a sys_var update function, the caller must hold a lock protecting the sys_var (LOCK_global_system_variables, a polylock for the variable, etc.).

Parameters
log_typeQUERY_LOG_SLOW or QUERY_LOG_GENERAL

◆ slow_log_write()

bool Query_logger::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.

Parameters
thdTHD of the statement being logged.
queryThe query string being logged.
query_lengthThe length of the query string.
aggregateTrue if writing log throttle record
lock_usecLock time, in microseconds. Only used when aggregate is true.
exec_usecExecution time, in microseconds. Only used when aggregate is true.
Returns
true if error, false otherwise.

Member Data Documentation

◆ file_log_handler

Log_to_file_event_handler* Query_logger::file_log_handler
private

◆ general_log_handler_list

Log_event_handler* Query_logger::general_log_handler_list[MAX_LOG_HANDLERS_NUM+1]
private

◆ LOCK_logger

mysql_rwlock_t Query_logger::LOCK_logger
private

RW-lock protecting Query_logger.

R-lock taken when writing to slow/general query log. W-lock taken when activating/deactivating logs.

◆ MAX_LOG_HANDLERS_NUM

const uint Query_logger::MAX_LOG_HANDLERS_NUM = 2
staticprivate

Currently we have only 2 kinds of logging functions: old-fashioned file logs and csv logging routines.

◆ slow_log_handler_list

Log_event_handler* Query_logger::slow_log_handler_list[MAX_LOG_HANDLERS_NUM+1]
private

NULL-terminated arrays of log handlers.

◆ table_log_handler

Log_to_csv_event_handler Query_logger::table_log_handler
private

Available log handlers.


The documentation for this class was generated from the following files: