mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-27087: Add thread ID and database / table, where the error occured
to SQL error plugin New plugin variable "with_db_and_thread_info" is added which prints the thread id and databse name to the logfile. the value is stored in variable "with_db_and_thread_info" log_sql_errors() is responsible for printing in the log. If detailed is enabled, print thread id and database name both, otherwise skip it.
This commit is contained in:
@@ -39,6 +39,7 @@ static unsigned int rate;
|
||||
static unsigned long long size_limit;
|
||||
static unsigned int rotations;
|
||||
static char rotate;
|
||||
static char with_db_and_thread_info;
|
||||
|
||||
static unsigned int count;
|
||||
LOGGER_HANDLE *logfile;
|
||||
@@ -67,12 +68,19 @@ static MYSQL_SYSVAR_STR(filename, filename,
|
||||
"The file to log sql errors to", NULL, NULL,
|
||||
"sql_errors.log");
|
||||
|
||||
static MYSQL_SYSVAR_BOOL(with_db_and_thread_info, with_db_and_thread_info,
|
||||
PLUGIN_VAR_READONLY | PLUGIN_VAR_OPCMDARG,
|
||||
"Show details about thread id and database name in the log",
|
||||
NULL, NULL,
|
||||
0);
|
||||
|
||||
static struct st_mysql_sys_var* vars[] = {
|
||||
MYSQL_SYSVAR(rate),
|
||||
MYSQL_SYSVAR(size_limit),
|
||||
MYSQL_SYSVAR(rotations),
|
||||
MYSQL_SYSVAR(rotate),
|
||||
MYSQL_SYSVAR(filename),
|
||||
MYSQL_SYSVAR(with_db_and_thread_info),
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -93,12 +101,24 @@ static void log_sql_errors(MYSQL_THD thd __attribute__((unused)),
|
||||
|
||||
count = 0;
|
||||
(void) localtime_r(&event_time, &t);
|
||||
logger_printf(logfile, "%04d-%02d-%02d %2d:%02d:%02d "
|
||||
if (with_db_and_thread_info)
|
||||
{
|
||||
logger_printf(logfile, "%llu %s %04d-%02d-%02d %2d:%02d:%02d "
|
||||
"%s ERROR %d: %s : %s \n",
|
||||
event->general_thread_id, event->database.str, t.tm_year + 1900,
|
||||
t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
|
||||
event->general_user, event->general_error_code,
|
||||
event->general_command, event->general_query);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger_printf(logfile, "%04d-%02d-%02d %2d:%02d:%02d "
|
||||
"%s ERROR %d: %s : %s\n",
|
||||
t.tm_year + 1900, t.tm_mon + 1,
|
||||
t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
|
||||
event->general_user, event->general_error_code,
|
||||
event->general_command, event->general_query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +177,7 @@ maria_declare_plugin(sql_errlog)
|
||||
0x0100,
|
||||
NULL,
|
||||
vars,
|
||||
"1.0",
|
||||
"1.1",
|
||||
MariaDB_PLUGIN_MATURITY_STABLE
|
||||
}
|
||||
maria_declare_plugin_end;
|
||||
|
Reference in New Issue
Block a user