From a70f7aad55fbb3b6a9a3cdeb8a83bd50df3f00e2 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 19 Jun 2017 06:25:10 +0300 Subject: [PATCH] Print thread_id instead of pthread_self to error log - Now we have same thread_id in general log, slow long and error log instead of a long meaningless thread number that may even change for one user. - Align error and slow log header with output - Extend thread_id with one number to handle nice printing up to ten million connections --- sql/log.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index 97982eed7fa..20ab472d04a 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2672,7 +2672,7 @@ bool MYSQL_LOG::open( mysqld_port, mysqld_unix_port #endif ); - end= strnmov(buff + len, "Time Id Command Argument\n", + end= strnmov(buff + len, "Time\t\t Id Command\tArgument\n", sizeof(buff) - len); if (my_b_write(&log_file, (uchar*) buff, (uint) (end-buff)) || flush_io_cache(&log_file)) @@ -2907,7 +2907,7 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, goto err; /* command_type, thread_id */ - size_t length= my_snprintf(buff, 32, "%5llu ", thread_id_arg); + size_t length= my_snprintf(buff, 32, "%6llu ", thread_id_arg); if (my_b_write(&log_file, (uchar*) buff, length)) goto err; @@ -8460,7 +8460,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer, time_t skr; struct tm tm_tmp; struct tm *start; - THD *thd; + THD *thd= 0; int tag_length= 0; char tag[NAME_LEN]; DBUG_ENTER("print_buffer_to_file"); @@ -8494,7 +8494,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer, start->tm_hour, start->tm_min, start->tm_sec, - (unsigned long) pthread_self(), + (unsigned long) (thd ? thd->thread_id : 0), (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ? "Warning" : "Note"), tag_length, tag,