]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Refactor log functions yet some
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 10 May 2010 19:34:44 +0000 (21:34 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 10 May 2010 19:37:19 +0000 (21:37 +0200)
ccache.h
util.c

index 7d50b2dd2002ac44b574c07df5d7a341b4f257c6..328cf0f56292c130c57991355de2c05f58495118 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -65,7 +65,6 @@ char *hash_result(struct mdfour *md);
 void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
 void hash_buffer(struct mdfour *md, const void *s, size_t len);
 
-void cc_log_no_newline(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
 void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
 void cc_log_executed_command(char **argv);
 void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
diff --git a/util.c b/util.c
index f7511a43e09b18cd092776885e37f2d339ef4e6d..f184ecc9e3f766ce434bbabe109aa9c4bd4eda01 100644 (file)
--- a/util.c
+++ b/util.c
@@ -42,7 +42,7 @@
 
 static FILE *logfile;
 
-static int init_log()
+static int init_log(void)
 {
        extern char *cache_logfile;
 
@@ -60,56 +60,41 @@ static int init_log()
        }
 }
 
-static void log_va_list(const char *format, va_list ap)
+static void log_prefix(void)
 {
-       if (!init_log()) {
-               return;
-       }
-
        fprintf(logfile, "[%-5d] ", getpid());
-       vfprintf(logfile, format, ap);
 }
 
 /*
- * Log a message to the CCACHE_LOGFILE location without newline and without
- * flushing.
+ * Write a message to the CCACHE_LOGFILE location (adding a newline).
  */
-void cc_log_no_newline(const char *format, ...)
+void cc_log(const char *format, ...)
 {
-       if (!init_log()) {
-               return;
-       }
-
        va_list ap;
-       va_start(ap, format);
-       log_va_list(format, ap);
-       va_end(ap);
-}
 
-/*
- * Log a message to the CCACHE_LOGFILE location adding a newline and flushing.
- */
-void cc_log(const char *format, ...)
-{
        if (!init_log()) {
                return;
        }
 
-       va_list ap;
+       log_prefix();
        va_start(ap, format);
-       log_va_list(format, ap);
+       vfprintf(logfile, format, ap);
        va_end(ap);
        fprintf(logfile, "\n");
        fflush(logfile);
 }
 
+/*
+ * Log an executed command to the CCACHE_LOGFILE location.
+ */
 void cc_log_executed_command(char **argv)
 {
        if (!init_log()) {
                return;
        }
 
-       cc_log_no_newline("Executing ");
+       log_prefix();
+       fprintf(logfile, "Executing ");
        print_command(logfile, argv);
        fflush(logfile);
 }