void cc_vlog(const char *format, va_list ap);
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
-void cc_log_without_flush(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
+void cc_bulklog(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void cc_log_argv(const char *prefix, char **argv);
void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void copy_fd(int fd_in, int fd_out);
}
static void
-log_prefix(void)
+log_prefix(bool log_updated_time)
{
#ifdef HAVE_GETTIMEOFDAY
char timestamp[100];
struct timeval tv;
struct tm *tm;
+ static char prefix[200];
- gettimeofday(&tv, NULL);
+ if (log_updated_time) {
+ gettimeofday(&tv, NULL);
#ifdef __MINGW64_VERSION_MAJOR
- tm = _localtime32(&tv.tv_sec);
+ tm = _localtime32(&tv.tv_sec);
#else
- tm = localtime(&tv.tv_sec);
+ tm = localtime(&tv.tv_sec);
#endif
- strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", tm);
- fprintf(logfile, "[%s.%06d %-5d] ", timestamp, (int)tv.tv_usec,
- (int)getpid());
+ strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", tm);
+ snprintf(prefix, sizeof(prefix),
+ "[%s.%06d %-5d] ", timestamp, (int)tv.tv_usec, (int)getpid());
+ }
+ fputs(prefix, logfile);
#else
fprintf(logfile, "[%-5d] ", (int)getpid());
#endif
#endif
}
-/*
- * Write a message to the log file (adding a newline) and flush.
- */
-void
-cc_vlog(const char *format, va_list ap)
+static void
+vlog(const char *format, va_list ap, bool log_updated_time)
{
if (!init_log()) {
return;
}
- log_prefix();
+ log_prefix(log_updated_time);
vfprintf(logfile, format, ap);
fprintf(logfile, "\n");
}
+/*
+ * Write a message to the log file (adding a newline) and flush.
+ */
+void
+cc_vlog(const char *format, va_list ap)
+{
+ vlog(format, ap, true);
+}
+
/*
* Write a message to the log file (adding a newline) and flush.
*/
{
va_list ap;
va_start(ap, format);
- cc_vlog(format, ap);
+ vlog(format, ap, true);
va_end(ap);
if (logfile) {
fflush(logfile);
}
/*
- * Write a message to the log file (adding a newline).
+ * Write a message to the log file (adding a newline) without flushing and with
+ * a reused timestamp.
*/
void
-cc_log_without_flush(const char *format, ...)
+cc_bulklog(const char *format, ...)
{
va_list ap;
va_start(ap, format);
- cc_vlog(format, ap);
+ vlog(format, ap, false);
va_end(ap);
}
return;
}
- log_prefix();
+ log_prefix(true);
fputs(prefix, logfile);
print_command(logfile, argv);
fflush(logfile);