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 2011-01-13 18:35:59.000000000 +0300
10 +++ b/client/client_priv.h 2011-01-13 18:38:21.000000000 +0300
12 OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
13 OPT_WRITE_BINLOG, OPT_DUMP_DATE,
21 diff -ruN a/client/mysql.cc b/client/mysql.cc
22 --- a/client/mysql.cc 2010-12-03 20:58:26.000000000 +0300
23 +++ b/client/mysql.cc 2011-01-13 18:38:21.000000000 +0300
25 #include "my_readline.h"
32 +#define MAX_SYSLOG_MESSAGE 900
34 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
37 default_pager_set= 0, opt_sigint_ignore= 0,
38 auto_vertical_output= 0,
39 show_warnings= 0, executing_query= 0, interrupted_query= 0,
41 + ignore_spaces= 0, opt_syslog= 0;
42 static my_bool debug_info_flag, debug_check_flag;
43 static my_bool column_types_flag;
44 static my_bool preserve_comments= 0;
46 void tee_fputs(const char *s, FILE *file);
47 void tee_puts(const char *s, FILE *file);
48 void tee_putc(int c, FILE *file);
49 +void write_syslog(String *buffer);
50 static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
51 /* The names of functions that actually do the manipulation. */
52 static int get_options(int argc,char **argv);
53 @@ -1563,6 +1569,10 @@
54 {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
55 &show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
58 + {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
59 + NO_ARG, 0, 0, 0, 0, 0, 0},
61 {"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
62 (uchar**) &opt_plugin_dir, (uchar**) &opt_plugin_dir, 0,
63 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
64 @@ -1667,6 +1677,11 @@
74 #ifdef EMBEDDED_LIBRARY
76 @@ -2020,6 +2035,40 @@
77 DBUG_RETURN((COMMANDS *) 0);
80 +void write_syslog(String *line){
82 + uint length= line->length();
83 + uint chunk_len= min(MAX_SYSLOG_MESSAGE, length);
84 + char *ptr= line->c_ptr_safe();
85 + char buff[MAX_SYSLOG_MESSAGE + 1];
89 + length-= chunk_len, ptr+= chunk_len, chunk_len= min(MAX_SYSLOG_MESSAGE,
93 + if (length == chunk_len)
94 + str= ptr; // last chunk => skip copy
97 + memcpy(buff, ptr, chunk_len);
98 + buff[chunk_len]= '\0';
102 + "SYSTEM_USER:'%s', MYSQL_USER:'%s', CONNECTION_ID:%lu, "
103 + "DB_SERVER:'%s', DB:'%s', QUERY:'%s'",
104 + getenv("SUDO_USER") ? getenv("SUDO_USER") :
105 + getenv("USER") ? getenv("USER") : "--",
106 + current_user ? current_user : "--",
107 + mysql_thread_id(&mysql),
108 + current_host ? current_host : "--",
109 + current_db ? current_db : "--",
115 static bool add_line(String &buffer,char *line,char *in_string,
116 bool *ml_comment, bool truncated)
117 @@ -2996,6 +3045,11 @@
122 + if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE){
123 + write_syslog(buffer);