1
# name : mysql-syslog.patch
6
# Any small change to this file in the main branch
7
# should be done or reviewed by the maintainer!
8
diff -ruN a/client/client_priv.h b/client/client_priv.h
9
--- a/client/client_priv.h 2010-08-08 14:12:42.229338865 +0400
10
+++ b/client/client_priv.h 2010-08-08 14:12:43.068089277 +0400
12
OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
13
OPT_WRITE_BINLOG, OPT_DUMP_DATE,
19
diff -ruN a/client/mysql.cc b/client/mysql.cc
20
--- a/client/mysql.cc 2010-08-08 14:12:42.229338865 +0400
21
+++ b/client/mysql.cc 2010-08-08 14:12:43.488088866 +0400
23
#include "my_readline.h"
30
#if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
33
default_pager_set= 0, opt_sigint_ignore= 0,
34
auto_vertical_output= 0,
35
show_warnings= 0, executing_query= 0, interrupted_query= 0,
37
+ opt_syslog=0, ignore_spaces= 0;
38
static my_bool debug_info_flag, debug_check_flag;
39
static my_bool column_types_flag;
40
static my_bool preserve_comments= 0;
42
void tee_fputs(const char *s, FILE *file);
43
void tee_puts(const char *s, FILE *file);
44
void tee_putc(int c, FILE *file);
45
+void write_syslog(char *line);
46
static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
47
/* The names of functions that actually do the manipulation. */
48
static int get_options(int argc,char **argv);
49
@@ -1561,6 +1565,10 @@
50
{"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
51
&show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
54
+ {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
55
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
57
{"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
58
(uchar**) &opt_plugin_dir, (uchar**) &opt_plugin_dir, 0,
59
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
60
@@ -1665,6 +1673,12 @@
65
+ /*if (connect_flag == CLIENT_INTERACTIVE){
66
+ printf("Logging queries to syslog.\n");
71
#ifdef EMBEDDED_LIBRARY
73
@@ -2014,6 +2028,39 @@
74
DBUG_RETURN((COMMANDS *) 0);
77
+void write_syslog(char *line){
81
+ for (i=0;i < strlen(line); i++){
82
+ buff[buff_pos] = line[i];
84
+ if (buff_pos >= 900){
87
+ syslog(LOG_INFO, "SYSTEM_USER:%s, MYSQL_USER:%s, CONNECTION_ID:%lu, DB_SERVER:%s, DB:%s, QUERY:%s",
88
+ getenv("SUDO_USER") ? getenv("SUDO_USER") :
89
+ getenv("USER") ? getenv("USER") : "--",
90
+ current_user ? current_user : "--",
91
+ mysql_thread_id(&mysql),
92
+ current_host ? current_host : "--",
93
+ current_db ? current_db : "--",
98
+ buff[buff_pos] = NULL;
99
+ syslog(LOG_INFO, "SYSTEM_USER:%s, MYSQL_USER:%s, CONNECTION_ID:%lu, DB_SERVER:%s, DB:%s, QUERY:%s",
100
+ getenv("SUDO_USER") ? getenv("SUDO_USER") :
101
+ getenv("USER") ? getenv("USER") : "--",
102
+ current_user ? current_user : "--",
103
+ mysql_thread_id(&mysql),
104
+ current_host ? current_host : "--",
105
+ current_db ? current_db : "--",
111
static bool add_line(String &buffer,char *line,char *in_string,
112
bool *ml_comment, bool truncated)
113
@@ -2986,6 +3033,11 @@
118
+ if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE){
119
+ write_syslog(buffer->c_ptr());