Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/6e468ee352d887023c3ff3fc1b8b557d67cedc12
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/6e468ee352d887023c3ff3fc1b8b557d67cedc12
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/6e468ee352d887023c3ff3fc1b8b557d67cedc12

The branch, vince/nslog has been created
        at  6e468ee352d887023c3ff3fc1b8b557d67cedc12 (commit)

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=6e468ee352d887023c3ff3fc1b8b557d67cedc12
commit 6e468ee352d887023c3ff3fc1b8b557d67cedc12
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    use nslog library for logging. working aside from duktape javascript

diff --git a/Makefile b/Makefile
index 1c2f517..3e70ea0 100644
--- a/Makefile
+++ b/Makefile
@@ -521,6 +521,7 @@ $(eval $(call feature_switch,DUKTAPE,Javascript 
(Duktape),,,,,))
 $(eval $(call pkg_config_find_and_add,libcss,CSS))
 $(eval $(call pkg_config_find_and_add,libdom,DOM))
 $(eval $(call pkg_config_find_and_add,libnsutils,nsutils))
+$(eval $(call pkg_config_find_and_add,libnslog,nslog))
 $(eval $(call pkg_config_find_and_add,libutf8proc,utf8proc))
 
 # Common libraries without pkg-config support
diff --git a/utils/log.c b/utils/log.c
index 15a7a9e..2450386 100644
--- a/utils/log.c
+++ b/utils/log.c
@@ -22,6 +22,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <nslog/nslog.h>
 
 #include "utils/config.h"
 #include "utils/sys_time.h"
@@ -36,6 +37,86 @@ bool verbose_log = false;
 /** The stream to which logging is sent */
 static FILE *logfile;
 
+NSLOG_DEFINE_CATEGORY(netsurf, "NetSurf default logging");
+
+/* Subtract the `struct timeval' values X and Y,
+   storing the result in RESULT.
+   Return 1 if the difference is negative, otherwise 0.
+*/
+
+static int
+timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
+{
+        /* Perform the carry for the later subtraction by updating y. */
+        if (x->tv_usec < y->tv_usec) {
+                int nsec = (int)(y->tv_usec - x->tv_usec) / 1000000 + 1;
+                y->tv_usec -= 1000000 * nsec;
+                y->tv_sec += nsec;
+        }
+        if ((int)(x->tv_usec - y->tv_usec) > 1000000) {
+                int nsec = (int)(x->tv_usec - y->tv_usec) / 1000000;
+                y->tv_usec += 1000000 * nsec;
+                y->tv_sec -= nsec;
+        }
+
+        /* Compute the time remaining to wait.
+           tv_usec is certainly positive. */
+        result->tv_sec = x->tv_sec - y->tv_sec;
+        result->tv_usec = x->tv_usec - y->tv_usec;
+
+        /* Return 1 if result is negative. */
+        return x->tv_sec < y->tv_sec;
+}
+
+/**
+ * Obtain a formatted string suitable for prepending to a log message
+ *
+ * \return formatted string of the time since first log call
+ */
+static const char *nslog_gettime(void)
+{
+        static struct timeval start_tv;
+        static char buff[32];
+
+        struct timeval tv;
+        struct timeval now_tv;
+
+        if (!timerisset(&start_tv)) {
+                gettimeofday(&start_tv, NULL);
+        }
+        gettimeofday(&now_tv, NULL);
+
+        timeval_subtract(&tv, &now_tv, &start_tv);
+
+        snprintf(buff, sizeof(buff),"(%ld.%06ld)",
+                 (long)tv.tv_sec, (long)tv.tv_usec);
+
+        return buff;
+}
+
+
+static void
+netsurf_render_log(void *_ctx,
+                   nslog_entry_context_t *ctx,
+                   const char *fmt,
+                   va_list args)
+{
+
+    fprintf(logfile,
+            "%s %.*s:%i %.*s: ",
+            nslog_gettime(),
+            ctx->filenamelen,
+            ctx->filename,
+            ctx->lineno,
+            ctx->funcnamelen,
+            ctx->funcname);
+
+    vfprintf(logfile, fmt, args);
+
+    /* Log entries aren't newline terminated add one for clarity */
+    fprintf(logfile, "\n");
+}
+
 nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
 {
        struct utsname utsname;
@@ -96,6 +177,16 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char 
**argv)
                verbose_log = false;
        }
 
+       if (nslog_set_render_callback(netsurf_render_log, NULL) != 
NSLOG_NO_ERROR) {
+               ret = NSERROR_INIT_FAILED;
+               verbose_log = false;
+
+       } else if (nslog_uncork() != NSLOG_NO_ERROR) {
+               ret = NSERROR_INIT_FAILED;
+               verbose_log = false;
+       }
+
+
        /* sucessfull logging initialisation so log system info */
        if (ret == NSERROR_OK) {
                LOG("NetSurf version '%s'", netsurf_version);
@@ -113,77 +204,3 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, 
char **argv)
 
        return ret;
 }
-
-#ifndef NDEBUG
-
-/* Subtract the `struct timeval' values X and Y,
-   storing the result in RESULT.
-   Return 1 if the difference is negative, otherwise 0.
-*/
-
-static int
-timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
-{
-       /* Perform the carry for the later subtraction by updating y. */
-       if (x->tv_usec < y->tv_usec) {
-               int nsec = (int)(y->tv_usec - x->tv_usec) / 1000000 + 1;
-               y->tv_usec -= 1000000 * nsec;
-               y->tv_sec += nsec;
-       }
-       if ((int)(x->tv_usec - y->tv_usec) > 1000000) {
-               int nsec = (int)(x->tv_usec - y->tv_usec) / 1000000;
-               y->tv_usec += 1000000 * nsec;
-               y->tv_sec -= nsec;
-       }
-
-       /* Compute the time remaining to wait.
-          tv_usec is certainly positive. */
-       result->tv_sec = x->tv_sec - y->tv_sec;
-       result->tv_usec = x->tv_usec - y->tv_usec;
-
-       /* Return 1 if result is negative. */
-       return x->tv_sec < y->tv_sec;
-}
-
-/**
- * Obtain a formatted string suitable for prepending to a log message
- *
- * \return formatted string of the time since first log call
- */
-static const char *nslog_gettime(void)
-{
-       static struct timeval start_tv;
-       static char buff[32];
-
-       struct timeval tv;
-       struct timeval now_tv;
-
-       if (!timerisset(&start_tv)) {
-               gettimeofday(&start_tv, NULL);
-       }
-       gettimeofday(&now_tv, NULL);
-
-       timeval_subtract(&tv, &now_tv, &start_tv);
-
-       snprintf(buff, sizeof(buff),"(%ld.%06ld)",
-                       (long)tv.tv_sec, (long)tv.tv_usec);
-
-       return buff;
-}
-
-void nslog_log(const char *file, const char *func, int ln, const char *format, 
...)
-{
-       va_list ap;
-
-       fprintf(logfile, "%s %s:%i %s: ", nslog_gettime(), file, ln, func);
-
-       va_start(ap, format);
-
-       vfprintf(logfile, format, ap);
-
-       va_end(ap);
-
-       fputc('\n', logfile);
-}
-
-#endif
diff --git a/utils/log.h b/utils/log.h
index 708016b..814949b 100644
--- a/utils/log.h
+++ b/utils/log.h
@@ -17,11 +17,12 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _NETSURF_LOG_H_
-#define _NETSURF_LOG_H_
+#ifndef NETSURF_LOG_H
+#define NETSURF_LOG_H
 
 #include <stdio.h>
 #include <stdbool.h>
+#include <nslog/nslog.h>
 
 #include "utils/errors.h"
 
@@ -43,28 +44,17 @@ typedef bool(nslog_ensure_t)(FILE *fptr);
  */
 extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv);
 
+NSLOG_DECLARE_CATEGORY(netsurf);
+
 #ifdef NDEBUG
 #  define LOG(format, ...) ((void) 0)
 #else
 
-extern void nslog_log(const char *file, const char *func, int ln, const char 
*format, ...) __attribute__ ((format (printf, 4, 5)));
-
-#  ifdef __GNUC__
-#    define LOG_FN __PRETTY_FUNCTION__
-#    define LOG_LN __LINE__
-#  elif defined(__CC_NORCROFT)
-#    define LOG_FN __func__
-#    define LOG_LN __LINE__
-#  else
-#    define LOG_FN ""
-#    define LOG_LN __LINE__
-#  endif
-
 #define LOG(format, args...)                                           \
        do {                                                            \
-               if (verbose_log) {                                      \
-                       nslog_log(__FILE__, LOG_FN, LOG_LN, format , ##args); \
-               }                                                       \
+               if (verbose_log) {                                      \
+                       NSLOG(netsurf, INFO, format , ##args);          \
+               }                                                       \
        } while(0)
 
 #endif


-----------------------------------------------------------------------


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to