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 --- a/client/client_priv.h
9 +++ b/client/client_priv.h
11 OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
12 OPT_WRITE_BINLOG, OPT_DUMP_DATE,
23 #include "my_readline.h"
30 +#define MAX_SYSLOG_MESSAGE 900
32 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
35 default_pager_set= 0, opt_sigint_ignore= 0,
36 auto_vertical_output= 0,
37 show_warnings= 0, executing_query= 0, interrupted_query= 0,
39 + ignore_spaces= 0, opt_syslog= 0;
40 static my_bool debug_info_flag, debug_check_flag;
41 static my_bool column_types_flag;
42 static my_bool preserve_comments= 0;
44 void tee_fputs(const char *s, FILE *file);
45 void tee_puts(const char *s, FILE *file);
46 void tee_putc(int c, FILE *file);
47 +void write_syslog(String *buffer);
48 static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
49 /* The names of functions that actually do the manipulation. */
50 static int get_options(int argc,char **argv);
51 @@ -1565,6 +1571,10 @@
52 {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
53 &show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
56 + {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
57 + NO_ARG, 0, 0, 0, 0, 0, 0},
59 {"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
60 &opt_plugin_dir, &opt_plugin_dir, 0,
61 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
62 @@ -1669,6 +1679,11 @@
72 #ifdef EMBEDDED_LIBRARY
74 @@ -2022,6 +2037,40 @@
75 DBUG_RETURN((COMMANDS *) 0);
78 +void write_syslog(String *line){
80 + uint length= line->length();
81 + uint chunk_len= min(MAX_SYSLOG_MESSAGE, length);
82 + char *ptr= line->c_ptr_safe();
83 + char buff[MAX_SYSLOG_MESSAGE + 1];
87 + length-= chunk_len, ptr+= chunk_len, chunk_len= min(MAX_SYSLOG_MESSAGE,
91 + if (length == chunk_len)
92 + str= ptr; // last chunk => skip copy
95 + memcpy(buff, ptr, chunk_len);
96 + buff[chunk_len]= '\0';
100 + "SYSTEM_USER:'%s', MYSQL_USER:'%s', CONNECTION_ID:%lu, "
101 + "DB_SERVER:'%s', DB:'%s', QUERY:'%s'",
102 + getenv("SUDO_USER") ? getenv("SUDO_USER") :
103 + getenv("USER") ? getenv("USER") : "--",
104 + current_user ? current_user : "--",
105 + mysql_thread_id(&mysql),
106 + current_host ? current_host : "--",
107 + current_db ? current_db : "--",
113 static bool add_line(String &buffer,char *line,char *in_string,
114 bool *ml_comment, bool truncated)
115 @@ -2998,6 +3047,11 @@
120 + if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE){
121 + write_syslog(buffer);