--- src/screen.c Fri Jan 25 18:46:56 2008 +0200 +++ src/screen.c Sat Jan 26 01:28:53 2008 +0200 @@ -228,10 +228,29 @@ static void static void flag_vputf(DCDisplayFlag flag, const char *format, va_list args) { - //va_list args2; + if (log_fh != NULL && log_flags & flag) { + char c_time[1024]; + time_t now = time(NULL); + struct tm _tm = {0}; + va_list args_dup; - //va_copy(args2, args); + if (NULL != localtime_r(&now, &_tm) && 0 != strftime(c_time, 1023, "%d.%m.%Y %H:%M:%S", &_tm)) { + fprintf(log_fh, "%s ", c_time); + } + // args would become undefined after xvasprintf() call, so make a copy + // of args to use it later below. + va_copy(args_dup, args); + char* msg = xvasprintf(format, args_dup); + va_end(args_dup); + + char* log_msg = main_to_log_string(msg); + free(msg); + fprintf(log_fh, log_msg); + free(log_msg); + fflush(log_fh); + } + if (display_flags & flag) { if (screen_state == SCREEN_SUSPENDED) { ptrv_append(suspend_msgs, xvasprintf(format, args)); @@ -243,21 +262,6 @@ flag_vputf(DCDisplayFlag flag, const cha vprintf(format, args); fflush(stdout); } - } - if (log_fh != NULL && log_flags & flag) { - char c_time[1024]; - time_t now = time(NULL); - struct tm _tm = {0}; - if (NULL != localtime_r(&now, &_tm) && 0 != strftime(c_time, 1023, "%d.%m.%Y %H:%M:%S", &_tm)) { - fprintf(log_fh, "%s ", c_time); - } - char* msg = xvasprintf(format, args); - //va_end(args2); - char* log_msg = main_to_log_string(msg); - free(msg); - fprintf(log_fh, log_msg); - free(log_msg); - fflush(log_fh); } }