From 3eab2275d093e9f3c77952e58af2abe82a1bc062 Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 12 Jun 2023 14:57:21 +0300 Subject: [PATCH] Added option sql_error_warnings to sql_error_log plugin --- mysql-test/suite/plugins/r/sql_error_log.result | 1 + plugin/sql_errlog/sql_errlog.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/plugins/r/sql_error_log.result b/mysql-test/suite/plugins/r/sql_error_log.result index 34c711a1e8d..0329949a231 100644 --- a/mysql-test/suite/plugins/r/sql_error_log.result +++ b/mysql-test/suite/plugins/r/sql_error_log.result @@ -8,6 +8,7 @@ sql_error_log_rate 1 sql_error_log_rotate OFF sql_error_log_rotations 9 sql_error_log_size_limit 1000000 +sql_error_log_warnings ON set global sql_error_log_rate=1; select * from t_doesnt_exist; ERROR 42S02: Table 'test.t_doesnt_exist' doesn't exist diff --git a/plugin/sql_errlog/sql_errlog.c b/plugin/sql_errlog/sql_errlog.c index 1454d4bd4dc..0b7771f1b89 100644 --- a/plugin/sql_errlog/sql_errlog.c +++ b/plugin/sql_errlog/sql_errlog.c @@ -39,6 +39,7 @@ static unsigned int rate; static unsigned long long size_limit; static unsigned int rotations; static char rotate; +static char warnings; static unsigned int count; LOGGER_HANDLE *logfile; @@ -67,12 +68,18 @@ static MYSQL_SYSVAR_STR(filename, filename, "The file to log sql errors to", NULL, NULL, "sql_errors.log"); +static MYSQL_SYSVAR_BOOL(warnings, warnings, + PLUGIN_VAR_OPCMDARG, + "Warnings. If set to 0, warnings are not logged.", + NULL, NULL, 1); + 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(warnings), NULL }; @@ -85,7 +92,7 @@ static void log_sql_errors(MYSQL_THD thd __attribute__((unused)), (const struct mysql_event_general*)ev; if (rate && (event->event_subclass == MYSQL_AUDIT_GENERAL_ERROR || - event->event_subclass == MYSQL_AUDIT_GENERAL_WARNING)) + (warnings && event->event_subclass == MYSQL_AUDIT_GENERAL_WARNING))) { const char *type= (event->event_subclass == MYSQL_AUDIT_GENERAL_ERROR ? "ERROR" : "WARNING");