diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2018-01-20 17:31:20 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2018-01-20 17:31:20 +0000 |
commit | 0dd48e83fbc246a881609b4c18ce10001ba1cc1a (patch) | |
tree | 7494cc81744799ab88f1503ac5ff044be2fcf4a5 | |
parent | e220b0fc2ede1dcbbe7e6e62c256e2ec297f26a3 (diff) | |
download | libcss-0dd48e83fbc246a881609b4c18ce10001ba1cc1a.tar.gz libcss-0dd48e83fbc246a881609b4c18ce10001ba1cc1a.tar.bz2 |
Add support for logging via libnslog.
Release builds minumum compiled level is warning.
Debug builds minimum compiled level is debug.
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | include/libcss/libcss.h | 4 | ||||
-rw-r--r-- | libcss.pc.in | 2 | ||||
-rw-r--r-- | src/utils/Makefile | 2 | ||||
-rw-r--r-- | src/utils/log.c | 17 | ||||
-rw-r--r-- | src/utils/log.h | 19 | ||||
-rw-r--r-- | test/csdetect.c | 26 | ||||
-rw-r--r-- | test/css21.c | 26 | ||||
-rw-r--r-- | test/lex-auto.c | 26 | ||||
-rw-r--r-- | test/lex.c | 26 | ||||
-rw-r--r-- | test/number.c | 26 | ||||
-rw-r--r-- | test/parse-auto.c | 26 | ||||
-rw-r--r-- | test/parse.c | 26 | ||||
-rw-r--r-- | test/parse2-auto.c | 26 | ||||
-rw-r--r-- | test/select.c | 26 |
16 files changed, 287 insertions, 5 deletions
@@ -28,7 +28,14 @@ ifneq ($(HOST),i586-pc-haiku) endif endif +ifeq ($(VARIANT),debug) + NSLOG_MIN_LOG=NSLOG_LEVEL_DEBUG +else + NSLOG_MIN_LOG=NSLOG_LEVEL_WARNING +endif + CFLAGS := -D_BSD_SOURCE -D_DEFAULT_SOURCE \ + -DNSLOG_COMPILED_MIN_LEVEL=$(NSLOG_MIN_LOG) \ -I$(CURDIR)/include/ -I$(CURDIR)/src \ $(WARNFLAGS) $(CFLAGS) ifneq ($(GCCVER),2) @@ -38,11 +45,11 @@ else CFLAGS := $(CFLAGS) -Dinline="__inline__" endif -# Parserutils & wapcaplet +# NSLog, Parserutils & Wapcaplet ifneq ($(findstring clean,$(MAKECMDGOALS)),clean) ifneq ($(PKGCONFIG),) - CFLAGS := $(CFLAGS) $(shell $(PKGCONFIG) libparserutils libwapcaplet --cflags) - LDFLAGS := $(LDFLAGS) $(shell $(PKGCONFIG) libparserutils libwapcaplet --libs) + CFLAGS := $(CFLAGS) $(shell $(PKGCONFIG) libnslog libparserutils libwapcaplet --cflags) + LDFLAGS := $(LDFLAGS) $(shell $(PKGCONFIG) libnslog libparserutils libwapcaplet --libs) else CFLAGS := $(CFLAGS) -I$(PREFIX)/include LDFLAGS := $(LDFLAGS) -lparserutils -lwapcaplet @@ -20,6 +20,7 @@ Requirements LibCSS also requires the following libraries to be installed: + + LibNSLog + LibParserUtils + LibWapcaplet diff --git a/include/libcss/libcss.h b/include/libcss/libcss.h index 89e83b5..9b0ae5e 100644 --- a/include/libcss/libcss.h +++ b/include/libcss/libcss.h @@ -13,6 +13,7 @@ extern "C" { #endif +#include <nslog/nslog.h> #include <libwapcaplet/libwapcaplet.h> #include <libcss/errors.h> @@ -24,6 +25,9 @@ extern "C" #include <libcss/stylesheet.h> #include <libcss/font_face.h> +/** Logging category for LibCSS. */ +NSLOG_DECLARE_CATEGORY(libcss); + #ifdef __cplusplus } #endif diff --git a/libcss.pc.in b/libcss.pc.in index 8df11b4..d1cba65 100644 --- a/libcss.pc.in +++ b/libcss.pc.in @@ -6,6 +6,6 @@ includedir=${prefix}/INCLUDEDIR Name: libcss Description: CSS parsing and selection library Version: VERSION -Requires: libparserutils, libwapcaplet +Requires: libnslog, libparserutils, libwapcaplet Libs: -L${libdir} -lcss Cflags: -I${includedir} diff --git a/src/utils/Makefile b/src/utils/Makefile index c317eea..f3fa8fb 100644 --- a/src/utils/Makefile +++ b/src/utils/Makefile @@ -1,4 +1,4 @@ # Sources -DIR_SOURCES := errors.c utils.c +DIR_SOURCES := errors.c log.c utils.c include $(NSBUILD)/Makefile.subdir diff --git a/src/utils/log.c b/src/utils/log.c new file mode 100644 index 0000000..f16c553 --- /dev/null +++ b/src/utils/log.c @@ -0,0 +1,17 @@ +/* + * This file is part of LibCSS. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2018 Michael Drake <tlsa@netsurf-browser.org> + */ + +#include <stddef.h> + +#include "utils/log.h" + +NSLOG_DEFINE_CATEGORY(libcss, "LibCSS"); + +NSLOG_DEFINE_SUBCATEGORY(libcss, libcss_selection, "Selection"); + +NSLOG_DEFINE_SUBCATEGORY(libcss_selection, libcss_selection_style_sharing, + "Computed style sharing"); diff --git a/src/utils/log.h b/src/utils/log.h new file mode 100644 index 0000000..6579d92 --- /dev/null +++ b/src/utils/log.h @@ -0,0 +1,19 @@ +/* + * This file is part of LibCSS. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2018 Michael Drake <tlsa@netsurf-browser.org> + */ + +#ifndef css_utils_log_h_ +#define css_utils_log_h_ + +#include <nslog/nslog.h> + +/** Logging sub-category for Selection. */ +NSLOG_DECLARE_CATEGORY(libcss_selection); + +/** Logging sub-category for Selection style sharing. */ +NSLOG_DECLARE_CATEGORY(libcss_selection_style_sharing); + +#endif diff --git a/test/csdetect.c b/test/csdetect.c index b8c8e3f..bbe4307 100644 --- a/test/csdetect.c +++ b/test/csdetect.c @@ -22,6 +22,20 @@ typedef struct line_ctx { bool inenc; } line_ctx; +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + static bool handle_line(const char *data, size_t datalen, void *pw); static void run_test(const uint8_t *data, size_t len, char *expected); @@ -34,6 +48,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + ctx.buflen = css__parse_filesize(argv[1]); if (ctx.buflen == 0) return 1; @@ -61,6 +85,8 @@ int main(int argc, char **argv) free(ctx.buf); + nslog_cleanup(); + printf("PASS\n"); return 0; diff --git a/test/css21.c b/test/css21.c index a29fae1..f8d3891 100644 --- a/test/css21.c +++ b/test/css21.c @@ -25,6 +25,20 @@ static css_error resolve_url(void *pw, return CSS_OK; } +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + int main(int argc, char **argv) { css_stylesheet_params params; @@ -41,6 +55,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1; params.level = CSS_LEVEL_21; params.charset = "UTF-8"; @@ -153,6 +177,8 @@ int main(int argc, char **argv) css_stylesheet_destroy(sheet); } + nslog_cleanup(); + printf("PASS\n"); return 0; diff --git a/test/lex-auto.c b/test/lex-auto.c index f4afec3..e7e7c83 100644 --- a/test/lex-auto.c +++ b/test/lex-auto.c @@ -42,6 +42,20 @@ static css_token_type string_to_type(const char *data, size_t len); static void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen); +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + int main(int argc, char **argv) { line_ctx ctx; @@ -51,6 +65,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + ctx.buflen = css__parse_filesize(argv[1]); if (ctx.buflen == 0) return 1; @@ -79,6 +103,8 @@ int main(int argc, char **argv) free(ctx.buf); free(ctx.exp); + nslog_cleanup(); + printf("PASS\n"); return 0; @@ -110,6 +110,20 @@ static void printToken(const css_token *token) #endif } +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + int main(int argc, char **argv) { parserutils_inputstream *stream; @@ -127,6 +141,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + for (i = 0; i < ITERATIONS; i++) { assert(parserutils_inputstream_create("UTF-8", CSS_CHARSET_DICTATED,css__charset_extract, @@ -190,6 +214,8 @@ int main(int argc, char **argv) parserutils_inputstream_destroy(stream); } + nslog_cleanup(); + printf("PASS\n"); return 0; diff --git a/test/number.c b/test/number.c index d255f4c..e3c2c8f 100644 --- a/test/number.c +++ b/test/number.c @@ -25,6 +25,20 @@ static void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen); static void print_css_fixed(char *buf, size_t len, css_fixed f); +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + int main(int argc, char **argv) { line_ctx ctx; @@ -34,6 +48,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + ctx.buflen = css__parse_filesize(argv[1]); if (ctx.buflen == 0) return 1; @@ -59,6 +83,8 @@ int main(int argc, char **argv) free(ctx.buf); + nslog_cleanup(); + printf("PASS\n"); return 0; diff --git a/test/parse-auto.c b/test/parse-auto.c index 58ccf9a..a298864 100644 --- a/test/parse-auto.c +++ b/test/parse-auto.c @@ -99,6 +99,20 @@ static void destroy_expected(line_ctx *ctx) } } +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + int main(int argc, char **argv) { line_ctx ctx; @@ -108,6 +122,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + ctx.buflen = css__parse_filesize(argv[1]); if (ctx.buflen == 0) return 1; @@ -143,6 +167,8 @@ int main(int argc, char **argv) assert(fail_because_lwc_leaked == false); + nslog_cleanup(); + printf("PASS\n"); return 0; diff --git a/test/parse.c b/test/parse.c index 0692fc7..c7017a9 100644 --- a/test/parse.c +++ b/test/parse.c @@ -66,6 +66,20 @@ static css_error event_handler(css_parser_event type, return CSS_OK; } +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + int main(int argc, char **argv) { css_parser_optparams params; @@ -82,6 +96,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + for (i = 0; i < ITERATIONS; i++) { assert(css__parser_create("UTF-8", CSS_CHARSET_DICTATED, &parser) == CSS_OK); @@ -129,6 +153,8 @@ int main(int argc, char **argv) } + nslog_cleanup(); + printf("PASS\n"); return 0; diff --git a/test/parse2-auto.c b/test/parse2-auto.c index ee717c3..ea833f9 100644 --- a/test/parse2-auto.c +++ b/test/parse2-auto.c @@ -57,6 +57,20 @@ printing_lwc_iterator(lwc_string *str, void *pw) fail_because_lwc_leaked = true; } +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + int main(int argc, char **argv) { line_ctx ctx; @@ -66,6 +80,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + ctx.buflen = css__parse_filesize(argv[1]); if (ctx.buflen == 0) return 1; @@ -99,6 +123,8 @@ int main(int argc, char **argv) assert(fail_because_lwc_leaked == false); + nslog_cleanup(); + printf("PASS\n"); return 0; diff --git a/test/select.c b/test/select.c index f21d937..923bf38 100644 --- a/test/select.c +++ b/test/select.c @@ -231,6 +231,20 @@ printing_lwc_iterator(lwc_string *str, void *pw) fail_because_lwc_leaked = true; } +static void test_logger( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, + va_list args) +{ + UNUSED(_ctx); + fprintf(stderr, "%s: %s: %s:%i: ", + nslog_level_name(ctx->level), + ctx->category->description, + ctx->filename, ctx->lineno); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + int main(int argc, char **argv) { line_ctx ctx; @@ -240,6 +254,16 @@ int main(int argc, char **argv) return 1; } + if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) { + printf("Unable to set log render callback\n"); + return 1; + } + + if (nslog_uncork() != NSLOG_NO_ERROR) { + printf("Failed to uncork log.\n"); + return 1; + } + memset(&ctx, 0, sizeof(ctx)); @@ -261,6 +285,8 @@ int main(int argc, char **argv) assert(fail_because_lwc_leaked == false); + nslog_cleanup(); + printf("PASS\n"); return 0; } |