Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/bb056e55b1374a72ed7784a461d027fbd6360b40
...commit
http://git.netsurf-browser.org/netsurf.git/commit/bb056e55b1374a72ed7784a461d027fbd6360b40
...tree
http://git.netsurf-browser.org/netsurf.git/tree/bb056e55b1374a72ed7784a461d027fbd6360b40
The branch, master has been updated
via bb056e55b1374a72ed7784a461d027fbd6360b40 (commit)
from 8b88e440905708ad9354fb72afff206d6208a760 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=bb056e55b1374a72ed7784a461d027fbd6360b40
commit bb056e55b1374a72ed7784a461d027fbd6360b40
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>
Sort out the logging so that -v etc do the right thing
diff --git a/Makefile b/Makefile
index 146b2f7..d6723e0 100644
--- a/Makefile
+++ b/Makefile
@@ -575,6 +575,13 @@ CXXFLAGS += -DNETSURF_HOMEPAGE=\"$(NETSURF_HOMEPAGE)\"
CFLAGS += -DNETSURF_LOG_LEVEL=$(NETSURF_LOG_LEVEL)
CXXFLAGS += -DNETSURF_LOG_LEVEL=$(NETSURF_LOG_LEVEL)
+# and the logging filter
+CFLAGS += -DNETSURF_BUILTIN_LOG_FILTER=\"$(NETSURF_BUILTIN_LOG_FILTER)\"
+CXXFLAGS += -DNETSURF_BUILTIN_LOG_FILTER=\"$(NETSURF_BUILTIN_LOG_FILTER)\"
+# and the verbose logging filter
+CFLAGS +=
-DNETSURF_BUILTIN_VERBOSE_FILTER=\"$(NETSURF_BUILTIN_VERBOSE_FILTER)\"
+CXXFLAGS +=
-DNETSURF_BUILTIN_VERBOSE_FILTER=\"$(NETSURF_BUILTIN_VERBOSE_FILTER)\"
+
# ----------------------------------------------------------------------------
# General make rules
# ----------------------------------------------------------------------------
diff --git a/Makefile.defaults b/Makefile.defaults
index d6637da..1f9ce5f 100644
--- a/Makefile.defaults
+++ b/Makefile.defaults
@@ -79,6 +79,11 @@ NETSURF_USE_NSLOG := AUTO
# The minimum logging level *compiled* into netsurf
# Valid options are: DEEPDEBUG, DEBUG, VERBOSE, INFO, WARNING, ERROR, CRITICAL
NETSURF_LOG_LEVEL := INFO
+# The log filter set during log initialisation before options are available
+NETSURF_BUILTIN_LOG_FILTER := level:WARNING
+# The log filter set during log initialisation before options are available
+# if the logging level is set to verbose
+NETSURF_BUILTIN_VERBOSE_FILTER := level:VERBOSE
# Enable stripping the NetSurf binary
# Valid options: YES, NO
diff --git a/desktop/options.h b/desktop/options.h
index d91898c..9b7064e 100644
--- a/desktop/options.h
+++ b/desktop/options.h
@@ -289,3 +289,8 @@ NSOPTION_COLOUR(sys_colour_ThreeDShadow, 0x00d5d5d5)
NSOPTION_COLOUR(sys_colour_Window, 0x00f1f1f1)
NSOPTION_COLOUR(sys_colour_WindowFrame, 0x004e4e4e)
NSOPTION_COLOUR(sys_colour_WindowText, 0x00000000)
+
+/** Filter for non-verbose logging */
+NSOPTION_STRING(log_filter, "level:WARNING")
+/** Filter for verbose logging */
+NSOPTION_STRING(verbose_filter, "level:VERBOSE")
diff --git a/utils/log.c b/utils/log.c
index 5ebe51f..68a470a 100644
--- a/utils/log.c
+++ b/utils/log.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include "utils/config.h"
+#include "utils/nsoption.h"
#include "utils/sys_time.h"
#include "utils/utsname.h"
#include "desktop/version.h"
@@ -105,21 +106,43 @@ netsurf_render_log(void *_ctx,
const char *fmt,
va_list args)
{
- if (verbose_log) {
- fprintf(logfile,
- "%s %.*s:%i %.*s: ",
- nslog_gettime(),
- ctx->filenamelen,
- ctx->filename,
- ctx->lineno,
- ctx->funcnamelen,
- ctx->funcname);
+ 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 */
+ fputc('\n', logfile);
+}
- vfprintf(logfile, fmt, args);
+/* exported interface documented in utils/log.h */
+nserror
+nslog_set_filter(const char *filter)
+{
+ nslog_error err;
+ nslog_filter_t *filt = NULL;
+
+ err = nslog_filter_from_text(filter, &filt);
+ if (err != NSLOG_NO_ERROR) {
+ if (err == NSLOG_NO_MEMORY)
+ return NSERROR_NOMEM;
+ else
+ return NSERROR_INVALID;
+ }
- /* Log entries aren't newline terminated add one for clarity */
- fputc('\n', logfile);
+ err = nslog_filter_set_active(filt, NULL);
+ if (err != NSLOG_NO_ERROR) {
+ nslog_filter_unref(filt);
+ return NSERROR_NOSPACE;
}
+
+ return NSERROR_OK;
}
#else
@@ -147,6 +170,15 @@ nslog_log(const char *file, const char *func, int ln,
const char *format, ...)
}
}
+/* exported interface documented in utils/log.h */
+nserror
+nslog_set_filter(const char *filter)
+{
+ (void)(filter);
+ return NSERROR_OK;
+}
+
+
#endif
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
@@ -195,7 +227,7 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char
**argv)
/* ensure we actually show logging */
verbose_log = true;
}
- } else if (verbose_log == true) {
+ } else {
/* default is logging to stderr */
logfile = stderr;
}
@@ -211,10 +243,14 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc,
char **argv)
#ifdef WITH_NSLOG
- if (nslog_set_render_callback(netsurf_render_log, NULL) !=
NSLOG_NO_ERROR) {
+ if (nslog_set_filter(verbose_log ?
+ NETSURF_BUILTIN_VERBOSE_FILTER :
+ NETSURF_BUILTIN_LOG_FILTER) != NSERROR_OK) {
+ ret = NSERROR_INIT_FAILED;
+ verbose_log = false;
+ } else 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;
@@ -241,3 +277,13 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc,
char **argv)
return ret;
}
+
+/* exported interface documented in utils/log.h */
+nserror
+nslog_set_filter_by_options()
+{
+ if (verbose_log)
+ return nslog_set_filter(nsoption_charp(verbose_filter));
+ else
+ return nslog_set_filter(nsoption_charp(log_filter));
+}
diff --git a/utils/log.h b/utils/log.h
index 7b5bcc3..e73c8c3 100644
--- a/utils/log.h
+++ b/utils/log.h
@@ -47,6 +47,18 @@ typedef bool(nslog_ensure_t)(FILE *fptr);
*/
extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv);
+/**
+ * Set the logging filter.
+ *
+ * Compiles and enables the given logging filter.
+ */
+extern nserror nslog_set_filter(const char *filter);
+
+/**
+ * Set the logging filter according to the options.
+ */
+extern nserror nslog_set_filter_by_options(void);
+
/* ensure a logging level is defined */
#ifndef NETSURF_LOG_LEVEL
#define NETSURF_LOG_LEVEL INFO
diff --git a/utils/nsoption.c b/utils/nsoption.c
index 15f89ca..09529a0 100644
--- a/utils/nsoption.c
+++ b/utils/nsoption.c
@@ -187,7 +187,7 @@ static void nsoption_validate(struct nsoption_s *opts,
struct nsoption_s *defs)
break;
}
}
- if (black == true) {
+ if (black == true && defs != NULL) {
for (cloop = NSOPTION_SYS_COLOUR_START;
cloop <= NSOPTION_SYS_COLOUR_END;
cloop++) {
@@ -209,6 +209,9 @@ static void nsoption_validate(struct nsoption_s *opts,
struct nsoption_s *defs)
opts[NSOPTION_max_retried_fetches].value.u) > 60) &&
(opts[NSOPTION_max_retried_fetches].value.u > 1))
opts[NSOPTION_max_retried_fetches].value.u--;
+
+ /* We ignore the result because we can't fail to validate. Yay */
+ (void)nslog_set_filter_by_options();
}
/**
@@ -820,6 +823,8 @@ nsoption_commandline(int *pargc, char **argv, struct
nsoption_s *opts)
}
*pargc -= (idx - 1);
+ nsoption_validate(opts, nsoptions_default);
+
return NSERROR_OK;
}
-----------------------------------------------------------------------
Summary of changes:
Makefile | 7 +++++
Makefile.defaults | 5 ++++
desktop/options.h | 5 ++++
utils/log.c | 76 ++++++++++++++++++++++++++++++++++++++++++-----------
utils/log.h | 12 +++++++++
utils/nsoption.c | 7 ++++-
6 files changed, 96 insertions(+), 16 deletions(-)
diff --git a/Makefile b/Makefile
index 146b2f7..d6723e0 100644
--- a/Makefile
+++ b/Makefile
@@ -575,6 +575,13 @@ CXXFLAGS += -DNETSURF_HOMEPAGE=\"$(NETSURF_HOMEPAGE)\"
CFLAGS += -DNETSURF_LOG_LEVEL=$(NETSURF_LOG_LEVEL)
CXXFLAGS += -DNETSURF_LOG_LEVEL=$(NETSURF_LOG_LEVEL)
+# and the logging filter
+CFLAGS += -DNETSURF_BUILTIN_LOG_FILTER=\"$(NETSURF_BUILTIN_LOG_FILTER)\"
+CXXFLAGS += -DNETSURF_BUILTIN_LOG_FILTER=\"$(NETSURF_BUILTIN_LOG_FILTER)\"
+# and the verbose logging filter
+CFLAGS +=
-DNETSURF_BUILTIN_VERBOSE_FILTER=\"$(NETSURF_BUILTIN_VERBOSE_FILTER)\"
+CXXFLAGS +=
-DNETSURF_BUILTIN_VERBOSE_FILTER=\"$(NETSURF_BUILTIN_VERBOSE_FILTER)\"
+
# ----------------------------------------------------------------------------
# General make rules
# ----------------------------------------------------------------------------
diff --git a/Makefile.defaults b/Makefile.defaults
index d6637da..1f9ce5f 100644
--- a/Makefile.defaults
+++ b/Makefile.defaults
@@ -79,6 +79,11 @@ NETSURF_USE_NSLOG := AUTO
# The minimum logging level *compiled* into netsurf
# Valid options are: DEEPDEBUG, DEBUG, VERBOSE, INFO, WARNING, ERROR, CRITICAL
NETSURF_LOG_LEVEL := INFO
+# The log filter set during log initialisation before options are available
+NETSURF_BUILTIN_LOG_FILTER := level:WARNING
+# The log filter set during log initialisation before options are available
+# if the logging level is set to verbose
+NETSURF_BUILTIN_VERBOSE_FILTER := level:VERBOSE
# Enable stripping the NetSurf binary
# Valid options: YES, NO
diff --git a/desktop/options.h b/desktop/options.h
index d91898c..9b7064e 100644
--- a/desktop/options.h
+++ b/desktop/options.h
@@ -289,3 +289,8 @@ NSOPTION_COLOUR(sys_colour_ThreeDShadow, 0x00d5d5d5)
NSOPTION_COLOUR(sys_colour_Window, 0x00f1f1f1)
NSOPTION_COLOUR(sys_colour_WindowFrame, 0x004e4e4e)
NSOPTION_COLOUR(sys_colour_WindowText, 0x00000000)
+
+/** Filter for non-verbose logging */
+NSOPTION_STRING(log_filter, "level:WARNING")
+/** Filter for verbose logging */
+NSOPTION_STRING(verbose_filter, "level:VERBOSE")
diff --git a/utils/log.c b/utils/log.c
index 5ebe51f..68a470a 100644
--- a/utils/log.c
+++ b/utils/log.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include "utils/config.h"
+#include "utils/nsoption.h"
#include "utils/sys_time.h"
#include "utils/utsname.h"
#include "desktop/version.h"
@@ -105,21 +106,43 @@ netsurf_render_log(void *_ctx,
const char *fmt,
va_list args)
{
- if (verbose_log) {
- fprintf(logfile,
- "%s %.*s:%i %.*s: ",
- nslog_gettime(),
- ctx->filenamelen,
- ctx->filename,
- ctx->lineno,
- ctx->funcnamelen,
- ctx->funcname);
+ 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 */
+ fputc('\n', logfile);
+}
- vfprintf(logfile, fmt, args);
+/* exported interface documented in utils/log.h */
+nserror
+nslog_set_filter(const char *filter)
+{
+ nslog_error err;
+ nslog_filter_t *filt = NULL;
+
+ err = nslog_filter_from_text(filter, &filt);
+ if (err != NSLOG_NO_ERROR) {
+ if (err == NSLOG_NO_MEMORY)
+ return NSERROR_NOMEM;
+ else
+ return NSERROR_INVALID;
+ }
- /* Log entries aren't newline terminated add one for clarity */
- fputc('\n', logfile);
+ err = nslog_filter_set_active(filt, NULL);
+ if (err != NSLOG_NO_ERROR) {
+ nslog_filter_unref(filt);
+ return NSERROR_NOSPACE;
}
+
+ return NSERROR_OK;
}
#else
@@ -147,6 +170,15 @@ nslog_log(const char *file, const char *func, int ln,
const char *format, ...)
}
}
+/* exported interface documented in utils/log.h */
+nserror
+nslog_set_filter(const char *filter)
+{
+ (void)(filter);
+ return NSERROR_OK;
+}
+
+
#endif
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
@@ -195,7 +227,7 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char
**argv)
/* ensure we actually show logging */
verbose_log = true;
}
- } else if (verbose_log == true) {
+ } else {
/* default is logging to stderr */
logfile = stderr;
}
@@ -211,10 +243,14 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc,
char **argv)
#ifdef WITH_NSLOG
- if (nslog_set_render_callback(netsurf_render_log, NULL) !=
NSLOG_NO_ERROR) {
+ if (nslog_set_filter(verbose_log ?
+ NETSURF_BUILTIN_VERBOSE_FILTER :
+ NETSURF_BUILTIN_LOG_FILTER) != NSERROR_OK) {
+ ret = NSERROR_INIT_FAILED;
+ verbose_log = false;
+ } else 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;
@@ -241,3 +277,13 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc,
char **argv)
return ret;
}
+
+/* exported interface documented in utils/log.h */
+nserror
+nslog_set_filter_by_options()
+{
+ if (verbose_log)
+ return nslog_set_filter(nsoption_charp(verbose_filter));
+ else
+ return nslog_set_filter(nsoption_charp(log_filter));
+}
diff --git a/utils/log.h b/utils/log.h
index 7b5bcc3..e73c8c3 100644
--- a/utils/log.h
+++ b/utils/log.h
@@ -47,6 +47,18 @@ typedef bool(nslog_ensure_t)(FILE *fptr);
*/
extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv);
+/**
+ * Set the logging filter.
+ *
+ * Compiles and enables the given logging filter.
+ */
+extern nserror nslog_set_filter(const char *filter);
+
+/**
+ * Set the logging filter according to the options.
+ */
+extern nserror nslog_set_filter_by_options(void);
+
/* ensure a logging level is defined */
#ifndef NETSURF_LOG_LEVEL
#define NETSURF_LOG_LEVEL INFO
diff --git a/utils/nsoption.c b/utils/nsoption.c
index 15f89ca..09529a0 100644
--- a/utils/nsoption.c
+++ b/utils/nsoption.c
@@ -187,7 +187,7 @@ static void nsoption_validate(struct nsoption_s *opts,
struct nsoption_s *defs)
break;
}
}
- if (black == true) {
+ if (black == true && defs != NULL) {
for (cloop = NSOPTION_SYS_COLOUR_START;
cloop <= NSOPTION_SYS_COLOUR_END;
cloop++) {
@@ -209,6 +209,9 @@ static void nsoption_validate(struct nsoption_s *opts,
struct nsoption_s *defs)
opts[NSOPTION_max_retried_fetches].value.u) > 60) &&
(opts[NSOPTION_max_retried_fetches].value.u > 1))
opts[NSOPTION_max_retried_fetches].value.u--;
+
+ /* We ignore the result because we can't fail to validate. Yay */
+ (void)nslog_set_filter_by_options();
}
/**
@@ -820,6 +823,8 @@ nsoption_commandline(int *pargc, char **argv, struct
nsoption_s *opts)
}
*pargc -= (idx - 1);
+ nsoption_validate(opts, nsoptions_default);
+
return NSERROR_OK;
}
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org