diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2017-06-11 10:08:37 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2017-06-11 10:08:37 +0100 |
commit | 8b4ce0ba86d0396bde2546dd248c863876da4106 (patch) | |
tree | 72ac2147cda97ddac20144a60e7b0644a0cc303f /test/explicitfilter.c | |
parent | 8052642eadfb95b244f978b10889dff51f9133f5 (diff) | |
download | libnslog-8b4ce0ba86d0396bde2546dd248c863876da4106.tar.gz libnslog-8b4ce0ba86d0396bde2546dd248c863876da4106.tar.bz2 |
Another step toward filters working
Diffstat (limited to 'test/explicitfilter.c')
-rw-r--r-- | test/explicitfilter.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/explicitfilter.c b/test/explicitfilter.c new file mode 100644 index 0000000..c7aca8a --- /dev/null +++ b/test/explicitfilter.c @@ -0,0 +1,50 @@ +/* + * Copyright 2017 Daniel Silverstone <dsilvers@netsurf-browser.org> + * + * This file is part of libnslog. + * + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + */ + +#include "nslog/nslog.h" + +#include <stdio.h> +#include <assert.h> + +NSLOG_DEFINE_CATEGORY(test, "Test category"); + +static void test_render_function( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, va_list args) +{ + (void)ctx; + fprintf(stderr, "%s %s:%d [%s] %s() ", + nslog_level_name(ctx->level), + ctx->filename, ctx->lineno, + ctx->category->name, + ctx->funcname); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + +int main(int argc, char **argv) +{ + nslog_set_render_callback(test_render_function, NULL); + nslog_uncork(); + + nslog_filter_t *cat_test, *cat_another; + + assert(nslog_filter_category_new("test", &cat_test) == NSLOG_NO_ERROR); + assert(nslog_filter_category_new("another", &cat_another) == NSLOG_NO_ERROR); + + NSLOG(test, INFO, "Hurrah, a message!"); + assert(nslog_filter_set_active(cat_test, NULL) == NSLOG_NO_ERROR); + NSLOG(test, INFO, "You should see me."); + assert(nslog_filter_set_active(cat_another, NULL) == NSLOG_NO_ERROR); + NSLOG(test, INFO, "You should not see me!"); + assert(nslog_filter_set_active(NULL, NULL) == NSLOG_NO_ERROR); + NSLOG(test, INFO, "You should see this one though."); + + return 0; +} |