summaryrefslogtreecommitdiff
path: root/sql/log.cc
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2004-09-01 04:12:09 +0300
committerunknown <monty@mysql.com>2004-09-01 04:12:09 +0300
commitc7d107254d2365f63dfb4fbd60232f93b1557a27 (patch)
tree4ad5995c2fe0e62dfd3c25bcb2a946ad44728c19 /sql/log.cc
parent1284432f945323b337297b91733810bfb1959d52 (diff)
parent200b51ad4e1cda8a512dedda2dcfe73f7fb20e21 (diff)
downloadmariadb-git-c7d107254d2365f63dfb4fbd60232f93b1557a27.tar.gz
Merge with 4.0
BitKeeper/etc/logging_ok: auto-union BitKeeper/deleted/.del-acconfig.h~8d2e3113fc8056da: Auto merged BitKeeper/deleted/.del-convert.cc~437689acaffb7446: Auto merged BitKeeper/deleted/.del-flush_block_commit-master.opt~3bcd295d5bf68796: Auto merged BitKeeper/deleted/.del-message.mc: Delete: VC++Files/sql/message.mc BitKeeper/deleted/.del-mysql_install.c~8c089740d79a92: Auto merged BitKeeper/deleted/.del-win1251.conf~b6bb6681f02917b6: Auto merged Build-tools/Bootstrap: Auto merged client/mysql.cc: Auto merged client/mysqladmin.c: Auto merged client/mysqlbinlog.cc: Auto merged client/mysqlcheck.c: Auto merged client/mysqldump.c: Auto merged client/mysqlimport.c: Auto merged client/mysqlmanager-pwgen.c: Auto merged client/mysqlshow.c: Auto merged client/mysqltest.c: Auto merged extra/my_print_defaults.c: Auto merged extra/perror.c: Auto merged extra/resolve_stack_dump.c: Auto merged extra/resolveip.c: Auto merged include/m_string.h: Auto merged include/my_getopt.h: Auto merged isam/isamchk.c: Auto merged isam/pack_isam.c: Auto merged myisam/mi_test1.c: Auto merged myisam/myisamchk.c: Auto merged myisam/myisampack.c: Auto merged sql/field.cc: Auto merged sql/gen_lex_hash.cc: Auto merged strings/strto.c: Auto merged strings/strtol.c: Auto merged strings/strtoll.c: Auto merged strings/strtoull.c: Auto merged support-files/Makefile.am: Auto merged tools/mysqlmanager.c: Auto merged
Diffstat (limited to 'sql/log.cc')
-rw-r--r--sql/log.cc157
1 files changed, 89 insertions, 68 deletions
diff --git a/sql/log.cc b/sql/log.cc
index f4ec5d9c731..08c1b31ed0d 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -43,37 +43,41 @@ static bool test_if_number(const char *str,
#ifdef __NT__
static int eventSource = 0;
-void setupWindowsEventSource()
-{
- if (eventSource) return;
-
- eventSource = 1;
- HKEY hRegKey = NULL;
- DWORD dwError = 0;
- TCHAR szPath[ MAX_PATH ];
- // Create the event source registry key
- dwError = RegCreateKey(HKEY_LOCAL_MACHINE,
- "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\MySQL",
- &hRegKey);
+void setup_windows_event_source()
+{
+ HKEY hRegKey= NULL;
+ DWORD dwError= 0;
+ TCHAR szPath[MAX_PATH];
+ DWORD dwTypes;
+
+ if (eventSource) // Ensure that we are only called once
+ return;
+ eventSource= 1;
- // Name of the PE module that contains the message resource
- GetModuleFileName(NULL, szPath, MAX_PATH);
+ // Create the event source registry key
+ dwError= RegCreateKey(HKEY_LOCAL_MACHINE,
+ "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\MySQL",
+ &hRegKey);
- // Register EventMessageFile
- dwError = RegSetValueEx(hRegKey, "EventMessageFile", 0, REG_EXPAND_SZ,
- (PBYTE) szPath, strlen(szPath)+1);
+ /* Name of the PE module that contains the message resource */
+ GetModuleFileName(NULL, szPath, MAX_PATH);
+ /* Register EventMessageFile */
+ dwError = RegSetValueEx(hRegKey, "EventMessageFile", 0, REG_EXPAND_SZ,
+ (PBYTE) szPath, strlen(szPath)+1);
+
- // Register supported event types
- DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
- dwError = RegSetValueEx(hRegKey, "TypesSupported", 0, REG_DWORD,
- (LPBYTE) &dwTypes, sizeof dwTypes);
+ /* Register supported event types */
+ dwTypes= (EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
+ EVENTLOG_INFORMATION_TYPE);
+ dwError= RegSetValueEx(hRegKey, "TypesSupported", 0, REG_DWORD,
+ (LPBYTE) &dwTypes, sizeof dwTypes);
- RegCloseKey(hRegKey);
+ RegCloseKey(hRegKey);
}
-#endif
+#endif /* __NT__ */
/****************************************************************************
@@ -1413,12 +1417,24 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u",
/* Write log events to reset the 'run environment' of the SQL command */
- if (thd && thd->options & OPTION_NO_FOREIGN_KEY_CHECKS)
+ if (thd)
{
- Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=1", 24, 0);
- e.set_log_pos(this);
- if (e.write(file))
- goto err;
+ if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS)
+ {
+ Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=1", 24, 0);
+ e.set_log_pos(this);
+ if (e.write(file))
+ goto err;
+ }
+#if MYSQL_VERSION_ID < 40100
+ if (thd->variables.convert_set)
+ {
+ Query_log_event e(thd, "SET CHARACTER SET DEFAULT", 25, 0);
+ e.set_log_pos(this);
+ if (e.write(file))
+ goto err;
+ }
+#endif
}
/*
@@ -1984,8 +2000,8 @@ void print_buffer_to_file(enum loglevel level, const char *buffer)
time_t skr;
struct tm tm_tmp;
struct tm *start;
-
- DBUG_ENTER("print_buffer_to_log");
+ DBUG_ENTER("print_buffer_to_file");
+ DBUG_PRINT("enter",("buffer: %s", buffer));
VOID(pthread_mutex_lock(&LOCK_error_log));
@@ -1999,13 +2015,13 @@ void print_buffer_to_file(enum loglevel level, const char *buffer)
start->tm_hour,
start->tm_min,
start->tm_sec,
- level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ? "WARNING" : "INFORMATION",
- buffer);
+ (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
+ "WARNING" : "INFORMATION"),
+ buffer);
fflush(stderr);
VOID(pthread_mutex_unlock(&LOCK_error_log));
-
DBUG_VOID_RETURN;
}
@@ -2019,6 +2035,7 @@ void sql_perror(const char *message)
#endif
}
+
bool flush_error_log()
{
bool result=0;
@@ -2204,93 +2221,95 @@ void MYSQL_LOG::report_pos_in_innodb()
}
#ifdef __NT__
-void print_buffer_to_nt_eventlog(enum loglevel level, char *buff, int buffLen)
+void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
+ uint length, int buffLen)
{
HANDLE event;
char *buffptr;
LPCSTR *buffmsgptr;
-
DBUG_ENTER("print_buffer_to_nt_eventlog");
- buffptr = buff;
- if (strlen(buff) > (uint)(buffLen-4))
+ buffptr= buff;
+ if (length > (uint)(buffLen-4))
{
- char *newBuff = new char[ strlen(buff) + 4 ];
+ char *newBuff= new char[length + 4];
strcpy(newBuff, buff);
- buffptr = newBuff;
+ buffptr= newBuff;
}
- strcat(buffptr, "\r\n\r\n");
- buffmsgptr = (LPCSTR*)&buffptr;
+ strmov(buffptr+length, "\r\n\r\n");
+ buffmsgptr= (LPCSTR*) &buffptr; // Keep windows happy
- setupWindowsEventSource();
- if (event = RegisterEventSource(NULL,"MySQL"))
+ setup_windows_event_source();
+ if ((event= RegisterEventSource(NULL,"MySQL")))
{
- switch (level){
+ switch (level) {
case ERROR_LEVEL:
- ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
+ ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, MSG_DEFAULT, NULL, 1, 0,
+ buffmsgptr, NULL);
break;
case WARNING_LEVEL:
- ReportEvent(event, EVENTLOG_WARNING_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
+ ReportEvent(event, EVENTLOG_WARNING_TYPE, 0, MSG_DEFAULT, NULL, 1, 0,
+ buffmsgptr, NULL);
break;
case INFORMATION_LEVEL:
- ReportEvent(event, EVENTLOG_INFORMATION_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
+ ReportEvent(event, EVENTLOG_INFORMATION_TYPE, 0, MSG_DEFAULT, NULL, 1,
+ 0, buffmsgptr, NULL);
break;
}
DeregisterEventSource(event);
}
- // if we created a string buffer, then delete it
+ /* if we created a string buffer, then delete it */
if (buffptr != buff)
delete[] buffptr;
DBUG_VOID_RETURN;
}
-#endif
+#endif /* __NT__ */
+
/*
- Prints a printf style message to the error log and, under NT, to the Windows event log.
+ Prints a printf style message to the error log and, under NT, to the
+ Windows event log.
SYNOPSIS
vprint_msg_to_log()
- event_type Type of event to write (Error, Warning, or Info)
- format Printf style format of message
- args va_list list of arguments for the message
+ event_type Type of event to write (Error, Warning, or Info)
+ format Printf style format of message
+ args va_list list of arguments for the message
NOTE
IMPLEMENTATION
- This function prints the message into a buffer and then sends that buffer to other
- functions to write that message to other logging sources.
+ This function prints the message into a buffer and then sends that buffer
+ to other functions to write that message to other logging sources.
RETURN VALUES
void
*/
+
void vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
{
char buff[1024];
+ uint length;
DBUG_ENTER("vprint_msg_to_log");
- my_vsnprintf(buff, sizeof(buff)-5, format, args);
-
+ length= my_vsnprintf(buff, sizeof(buff)-5, format, args);
print_buffer_to_file(level, buff);
-#ifndef DBUG_OFF
- DBUG_PRINT("error",("%s",buff));
-#endif
-
#ifdef __NT__
- print_buffer_to_nt_eventlog(level, buff, sizeof(buff));
+ print_buffer_to_nt_eventlog(level, buff, length, sizeof(buff));
#endif
DBUG_VOID_RETURN;
}
-void sql_print_error(const char *format, ...)
+void sql_print_error(const char *format, ...)
{
+ va_list args;
DBUG_ENTER("sql_print_error");
- va_list args;
va_start(args, format);
vprint_msg_to_log(ERROR_LEVEL, format, args);
va_end(args);
@@ -2298,11 +2317,12 @@ void sql_print_error(const char *format, ...)
DBUG_VOID_RETURN;
}
-void sql_print_warning(const char *format, ...)
+
+void sql_print_warning(const char *format, ...)
{
+ va_list args;
DBUG_ENTER("sql_print_warning");
- va_list args;
va_start(args, format);
vprint_msg_to_log(WARNING_LEVEL, format, args);
va_end(args);
@@ -2310,11 +2330,12 @@ void sql_print_warning(const char *format, ...)
DBUG_VOID_RETURN;
}
-void sql_print_information(const char *format, ...)
+
+void sql_print_information(const char *format, ...)
{
+ va_list args;
DBUG_ENTER("sql_print_information");
- va_list args;
va_start(args, format);
vprint_msg_to_log(INFORMATION_LEVEL, format, args);
va_end(args);