added fcts to log fcts
authorJean-Philippe Orsini <jeanfi@gmail.com>
Sat, 30 Nov 2013 10:42:30 +0000 (10:42 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Sat, 30 Nov 2013 10:42:30 +0000 (10:42 +0000)
switched to c99 to be sure that __func__ exists

configure.ac
src/log.c
src/log.h

index 01daed8..423a386 100644 (file)
@@ -11,6 +11,7 @@ AC_CONFIG_HEADERS([config.h])
 
 # Checks for programs.
 AC_PROG_CC
+AC_PROG_CC_C99
 AM_PROG_CC_C_O
 
 # Checks for header files.
index 7b4331f..ad7295f 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -55,7 +55,7 @@ void log_close()
 
 
 #define LOG_BUFFER 4096
-static void vlogf(int lvl, const char *fmt, va_list ap)
+static void vlogf(int lvl, const char *fct, const char *fmt, va_list ap)
 {
        char buffer[1 + LOG_BUFFER];
        char *lvl_str, *t;
@@ -89,7 +89,11 @@ static void vlogf(int lvl, const char *fmt, va_list ap)
                return ;
 
        if (file && lvl <= log_level) {
-               fprintf(file, "[%s] %s %s\n", t, lvl_str, buffer);
+               if (fct)
+                       fprintf(file, 
+                               "[%s] %s %s(): %s\n", t, lvl_str, fct, buffer);
+               else
+                       fprintf(file, "[%s] %s %s\n", t, lvl_str, buffer);
                fflush(file);
        } else {
                t = NULL;
@@ -101,8 +105,11 @@ static void vlogf(int lvl, const char *fmt, va_list ap)
                else
                        stdf = stdout;
 
-
-               fprintf(stdf, "[%s] %s %s\n", t, lvl_str, buffer);
+               if (fct)
+                       fprintf(file, 
+                               "[%s] %s %s(): %s\n", t, lvl_str, fct, buffer);
+               else
+                       fprintf(stdf, "[%s] %s %s\n", t, lvl_str, buffer);
        }
 
        free(t);
@@ -113,7 +120,7 @@ void log_printf(int lvl, const char *fmt, ...)
        va_list ap;
 
        va_start(ap, fmt);
-       vlogf(lvl, fmt, ap);
+       vlogf(lvl, NULL, fmt, ap);
        va_end(ap);
 }
 
@@ -125,7 +132,7 @@ void log_debug(const char *fmt, ...)
                return ;
 
        va_start(ap, fmt);
-       vlogf(LOG_DEBUG, fmt, ap);
+       vlogf(LOG_DEBUG, NULL, fmt, ap);
        va_end(ap);
 }
 
@@ -134,7 +141,7 @@ void log_err(const char *fmt, ...)
        va_list ap;
 
        va_start(ap, fmt);
-       vlogf(LOG_ERR, fmt, ap);
+       vlogf(LOG_ERR, NULL, fmt, ap);
        va_end(ap);
 }
 
@@ -143,7 +150,7 @@ void log_warn(const char *fmt, ...)
        va_list ap;
 
        va_start(ap, fmt);
-       vlogf(LOG_WARN, fmt, ap);
+       vlogf(LOG_WARN, NULL, fmt, ap);
        va_end(ap);
 }
 
@@ -152,6 +159,15 @@ void log_info(const char *fmt, ...)
        va_list ap;
 
        va_start(ap, fmt);
-       vlogf(LOG_INFO, fmt, ap);
+       vlogf(LOG_INFO, NULL, fmt, ap);
+       va_end(ap);
+}
+
+void log_fct(const char *fct, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       vlogf(LOG_DEBUG, fct, fmt, ap);
        va_end(ap);
 }
index 16d3282..15be241 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -27,6 +27,7 @@ enum log_level {
 };
 
 void log_open(const char *path);
+void log_close();
 
 void log_printf(int lvl, const char *fmt, ...);
 void log_debug(const char *fmt, ...);
@@ -34,7 +35,10 @@ void log_err(const char *fmt, ...);
 void log_info(const char *fmt, ...);
 void log_warn(const char *fmt, ...);
 
-void log_close();
+void log_fct(const char *fct,const char *fmt, ...);
+
+#define log_fct_enter() log_fct(__func__, "ENTER");
+#define log_fct_exit() log_fct(__func__, "EXIT");
 
 /* level of the log file. */
 extern int log_level;