summaryrefslogtreecommitdiffstats
path: root/plugin/sql_errlog
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:39:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:39:13 +0000
commit86fbb58c3ac0865482819c10a3e81f2eea001c36 (patch)
tree28c9e526ea739c6f9b89e36115e1e2698bddf981 /plugin/sql_errlog
parentReleasing progress-linux version 1:10.11.6-2~progress7.99u1. (diff)
downloadmariadb-86fbb58c3ac0865482819c10a3e81f2eea001c36.tar.xz
mariadb-86fbb58c3ac0865482819c10a3e81f2eea001c36.zip
Merging upstream version 1:10.11.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugin/sql_errlog')
-rw-r--r--plugin/sql_errlog/sql_errlog.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/plugin/sql_errlog/sql_errlog.c b/plugin/sql_errlog/sql_errlog.c
index 0b7771f1..3631cd1d 100644
--- a/plugin/sql_errlog/sql_errlog.c
+++ b/plugin/sql_errlog/sql_errlog.c
@@ -15,6 +15,7 @@
#include <mysql/plugin_audit.h>
#include <stdio.h>
+#include <string.h>
#include <time.h>
#include <mysql/service_logger.h>
@@ -40,6 +41,7 @@ static unsigned long long size_limit;
static unsigned int rotations;
static char rotate;
static char warnings;
+static char with_db_and_thread_info;
static unsigned int count;
LOGGER_HANDLE *logfile;
@@ -73,6 +75,12 @@ static MYSQL_SYSVAR_BOOL(warnings, warnings,
"Warnings. If set to 0, warnings are not logged.",
NULL, NULL, 1);
+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),
@@ -80,6 +88,7 @@ static struct st_mysql_sys_var* vars[] = {
MYSQL_SYSVAR(rotate),
MYSQL_SYSVAR(filename),
MYSQL_SYSVAR(warnings),
+ MYSQL_SYSVAR(with_db_and_thread_info),
NULL
};
@@ -90,6 +99,7 @@ static void log_sql_errors(MYSQL_THD thd __attribute__((unused)),
{
const struct mysql_event_general *event =
(const struct mysql_event_general*)ev;
+
if (rate &&
(event->event_subclass == MYSQL_AUDIT_GENERAL_ERROR ||
(warnings && event->event_subclass == MYSQL_AUDIT_GENERAL_WARNING)))
@@ -103,12 +113,35 @@ 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)
+ {
+ if (event->database.str)
+ {
+ logger_printf(logfile, "%04d-%02d-%02d %2d:%02d:%02d %lu "
+ "%s %`s %s %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_thread_id, event->general_user,
+ event->database.str, type,
+ event->general_error_code, event->general_command, event->general_query);
+ }
+ else
+ {
+ logger_printf(logfile, "%04d-%02d-%02d %2d:%02d:%02d %lu "
+ "%s NULL %s %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_thread_id, event->general_user, type,
+ event->general_error_code, event->general_command, event->general_query);
+ }
+ }
+ else
+ {
+ logger_printf(logfile, "%04d-%02d-%02d %2d:%02d:%02d "
"%s %s %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, type, event->general_error_code,
- event->general_command, event->general_query);
+ t.tm_year + 1900, t.tm_mon + 1,
+ t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
+ event->general_user, type, event->general_error_code,
+ event->general_command, event->general_query);
+ }
}
}
}
@@ -167,7 +200,7 @@ maria_declare_plugin(sql_errlog)
0x0100,
NULL,
vars,
- "1.0",
+ "1.1",
MariaDB_PLUGIN_MATURITY_STABLE
}
maria_declare_plugin_end;