Skip to content

Instantly share code, notes, and snippets.

@yoku0825
Created May 16, 2013 02:08
Show Gist options
  • Save yoku0825/5588915 to your computer and use it in GitHub Desktop.
Save yoku0825/5588915 to your computer and use it in GitHub Desktop.
MySQL5.5.31とMySQL5.6.11のログ中のタイムスタンプの変更点あたり。 print_buffer_to_fileはmysqldの全般的なログ記録、ut_print_timestampはInnoDB独自のログ記録の時に呼び出されてる。
mysql-5.5.31/sql/log.cc: print_buffer_to_file
5900 #ifndef EMBEDDED_LIBRARY
5901 static void print_buffer_to_file(enum loglevel level, const char *buffer,
5902 size_t length)
5903 {
5904 time_t skr;
5905 struct tm tm_tmp;
5906 struct tm *start;
5907 DBUG_ENTER("print_buffer_to_file");
5908 DBUG_PRINT("enter",("buffer: %s", buffer));
5909
5910 mysql_mutex_lock(&LOCK_error_log);
5911
5912 skr= my_time(0);
5913 localtime_r(&skr, &tm_tmp);
5914 start=&tm_tmp;
5915
5916 fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %.*s\n",
5917 start->tm_year % 100,
5918 start->tm_mon+1,
5919 start->tm_mday,
5920 start->tm_hour,
5921 start->tm_min,
5922 start->tm_sec,
5923 (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
5924 "Warning" : "Note"),
5925 (int) length, buffer);
5926
5927 fflush(stderr);
5928
5929 mysql_mutex_unlock(&LOCK_error_log);
5930 DBUG_VOID_RETURN;
5931 }
mysql-5.5.31/storage/innobase/ut0ut.c: ut_print_timestamp
229 UNIV_INTERN
230 void
231 ut_print_timestamp(
232 /*===============*/
233 FILE* file) /*!< in: file where to print */
234 {
235 #ifdef __WIN__
236 SYSTEMTIME cal_tm;
237
238 GetLocalTime(&cal_tm);
239
240 fprintf(file,"%02d%02d%02d %2d:%02d:%02d",
241 (int)cal_tm.wYear % 100,
242 (int)cal_tm.wMonth,
243 (int)cal_tm.wDay,
244 (int)cal_tm.wHour,
245 (int)cal_tm.wMinute,
246 (int)cal_tm.wSecond);
247 #else
248 #ifdef HAVE_LOCALTIME_R
249 struct tm cal_tm;
250 #endif
251 struct tm* cal_tm_ptr;
252 time_t tm;
253
254 time(&tm);
255
256 #ifdef HAVE_LOCALTIME_R
257 localtime_r(&tm, &cal_tm);
258 cal_tm_ptr = &cal_tm;
259 #else
260 cal_tm_ptr = localtime(&tm);
261 #endif
262 fprintf(file,"%02d%02d%02d %2d:%02d:%02d",
263 cal_tm_ptr->tm_year % 100,
264 cal_tm_ptr->tm_mon + 1,
265 cal_tm_ptr->tm_mday,
266 cal_tm_ptr->tm_hour,
267 cal_tm_ptr->tm_min,
268 cal_tm_ptr->tm_sec);
269 #endif
270 }
mysql-5.5.31/scripts/mysqld_safe: log_generic
120 log_generic () {
121 priority="$1"
122 shift
123
124 msg="`date +'%y%m%d %H:%M:%S'` mysqld_safe $*"
125 echo "$msg"
126 case $logging in
127 init) ;; # Just echo the message, don't save it anywhere
128 file) echo "$msg" >> "$err_log" ;;
129 syslog) logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;;
130 *)
131 echo "Internal program error (non-fatal):" \
132 " unknown logging method '$logging'" >&2
133 ;;
134 esac
135 }
mysql-5.6.11/sql/log.cc: print_buffer_to_file
2265 #ifndef EMBEDDED_LIBRARY
2266 static void print_buffer_to_file(enum loglevel level, const char *buffer,
2267 size_t length)
2268 {
2269 time_t skr;
2270 struct tm tm_tmp;
2271 struct tm *start;
2272 DBUG_ENTER("print_buffer_to_file");
2273 DBUG_PRINT("enter",("buffer: %s", buffer));
2274
2275 mysql_mutex_lock(&LOCK_error_log);
2276
2277 skr= my_time(0);
2278 localtime_r(&skr, &tm_tmp);
2279 start=&tm_tmp;
2280
2281 fprintf(stderr, "%d-%02d-%02d %02d:%02d:%02d %lu [%s] %.*s\n",
2282 start->tm_year + 1900,
2283 start->tm_mon + 1,
2284 start->tm_mday,
2285 start->tm_hour,
2286 start->tm_min,
2287 start->tm_sec,
2288 current_pid,
2289 (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
2290 "Warning" : "Note"),
2291 (int) length, buffer);
2292
2293 fflush(stderr);
2294
2295 mysql_mutex_unlock(&LOCK_error_log);
2296 DBUG_VOID_RETURN;
2297 }
mysql-5.6.11/storage/innobase/ut/ut0ut.cc: ut_print_timestamp
214 /**********************************************************//**
215 Prints a timestamp to a file. */
216 UNIV_INTERN
217 void
218 ut_print_timestamp(
219 /*===============*/
220 FILE* file) /*!< in: file where to print */
221 {
222 ulint thread_id = 0;
223
224 #ifndef UNIV_INNOCHECKSUM
225 thread_id = os_thread_pf(os_thread_get_curr_id());
226 #endif
227
228 #ifdef __WIN__
229 SYSTEMTIME cal_tm;
230
231 GetLocalTime(&cal_tm);
232
233 fprintf(file, "%d-%02d-%02d %02d:%02d:%02d %lx",
234 (int) cal_tm.wYear,
235 (int) cal_tm.wMonth,
236 (int) cal_tm.wDay,
237 (int) cal_tm.wHour,
238 (int) cal_tm.wMinute,
239 (int) cal_tm.wSecond,
240 thread_id);
241 #else
242 struct tm* cal_tm_ptr;
243 time_t tm;
244
245 #ifdef HAVE_LOCALTIME_R
246 struct tm cal_tm;
247 time(&tm);
248 localtime_r(&tm, &cal_tm);
249 cal_tm_ptr = &cal_tm;
250 #else
251 time(&tm);
252 cal_tm_ptr = localtime(&tm);
253 #endif
254 fprintf(file, "%d-%02d-%02d %02d:%02d:%02d %lx",
255 cal_tm_ptr->tm_year + 1900,
256 cal_tm_ptr->tm_mon + 1,
257 cal_tm_ptr->tm_mday,
258 cal_tm_ptr->tm_hour,
259 cal_tm_ptr->tm_min,
260 cal_tm_ptr->tm_sec,
261 thread_id);
262 #endif
263 }
mysql-5.6.11/scripts/mysqld_safe: log_generic
121 log_generic () {
122 priority="$1"
123 shift
124
125 msg="`date +'%y%m%d %H:%M:%S'` mysqld_safe $*"
126 echo "$msg"
127 case $logging in
128 init) ;; # Just echo the message, don't save it anywhere
129 file) echo "$msg" >> "$err_log" ;;
130 syslog) logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;;
131 *)
132 echo "Internal program error (non-fatal):" \
133 " unknown logging method '$logging'" >&2
134 ;;
135 esac
136 }
@yoku0825
Copy link
Author

mysql-5.6.11/storage/innobase/ut0ut.cc: ut_sprintf_timestamp()とかut_sprintf_timestamp_without_extra_chars()は2桁年を返すけど、これは「ログ本文中に何かの時間を書く」時に呼び出されてるぽい。

fprintfじゃなくてsprintfで変数に値を突っ込んでるし。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment