libnslog
nslog.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Daniel Silverstone <dsilvers@netsurf-browser.org>
3 *
4 * This file is part of libnslog.
5 *
6 * Licensed under the MIT License,
7 * http://www.opensource.org/licenses/mit-license.php
8 */
9
15#ifndef NSLOG_NSLOG_H_
16#define NSLOG_NSLOG_H_
17
18#include <stdarg.h>
19
31typedef enum {
40
49const char *nslog_level_name(nslog_level level);
50
61
62#define NSLOG_LEVEL_DD NSLOG_LEVEL_DEEPDEBUG
63#define NSLOG_LEVEL_DBG NSLOG_LEVEL_DEBUG
64#define NSLOG_LEVEL_CHAT NSLOG_LEVEL_VERBOSE
65#define NSLOG_LEVEL_WARN NSLOG_LEVEL_WARNING
66#define NSLOG_LEVEL_ERR NSLOG_LEVEL_ERROR
67#define NSLOG_LEVEL_CRIT NSLOG_LEVEL_CRITICAL
68
69#ifndef NSLOG_COMPILED_MIN_LEVEL
78#define NSLOG_COMPILED_MIN_LEVEL NSLOG_LEVEL_DEBUG
79#endif
80
92typedef struct nslog_category_s {
93 const char *cat_name;
94 const char *description;
96 char *name;
97 int namelen;
100
109typedef struct nslog_entry_context_s {
112 const char *filename;
114 const char *funcname;
116 int lineno;
118
127#define NSLOG_DECLARE_CATEGORY(catname) \
128 extern nslog_category_t __nslog_category_##catname
129
139#define NSLOG_DEFINE_CATEGORY(catname, description) \
140 nslog_category_t __nslog_category_##catname = { \
141 #catname, \
142 description, \
143 NULL, \
144 NULL, \
145 0, \
146 NULL, \
147 }
148
162#define NSLOG_DEFINE_SUBCATEGORY(parentcatname, catname, description) \
163 nslog_category_t __nslog_category_##catname = { \
164 #catname, \
165 description, \
166 &__nslog_category_##parentcatname, \
167 NULL, \
168 0, \
169 NULL, \
170 }
171
184#define NSLOG(catname, level, logmsg, args...) \
185 do { \
186 if (NSLOG_LEVEL_##level >= NSLOG_COMPILED_MIN_LEVEL) { \
187 static nslog_entry_context_t _nslog_ctx = { \
188 &__nslog_category_##catname, \
189 NSLOG_LEVEL_##level, \
190 __FILE__, \
191 sizeof(__FILE__) - 1, \
192 __PRETTY_FUNCTION__, \
193 sizeof(__PRETTY_FUNCTION__) - 1, \
194 __LINE__, \
195 }; \
196 nslog__log(&_nslog_ctx, logmsg, ##args); \
197 } \
198 } while(0)
199
211 const char *pattern,
212 ...) __attribute__ ((format (printf, 2, 3)));
213
221typedef enum {
227
242typedef void (*nslog_callback)(void *context, nslog_entry_context_t *ctx,
243 const char *fmt, va_list args);
244
256
270
287void nslog_cleanup(void);
288
302typedef struct nslog_filter_s nslog_filter_t;
303
319 nslog_filter_t **filter);
335 nslog_filter_t **filter);
336
351 nslog_filter_t **filter);
352
367 nslog_filter_t **filter);
368
384 nslog_filter_t **filter);
385
399 nslog_filter_t *right,
400 nslog_filter_t **filter);
401
415 nslog_filter_t *right,
416 nslog_filter_t **filter);
417
430 nslog_filter_t *right,
431 nslog_filter_t **filter);
432
444 nslog_filter_t **filter);
445
458
471
484 nslog_filter_t **prev);
485
486
499
515 nslog_filter_t **output);
516
517#endif /* NSLOG_NSLOG_H_ */
nslog_filter_t * nslog_filter_ref(nslog_filter_t *filter)
nslog_error nslog_filter_filename_new(const char *filename, nslog_filter_t **filter)
nslog_error nslog_filter_or_new(nslog_filter_t *left, nslog_filter_t *right, nslog_filter_t **filter)
const char * nslog_level_name(nslog_level level)
nslog_error nslog_set_render_callback(nslog_callback cb, void *context)
nslog_error nslog_filter_xor_new(nslog_filter_t *left, nslog_filter_t *right, nslog_filter_t **filter)
void nslog_cleanup(void)
struct nslog_entry_context_s nslog_entry_context_t
nslog_error nslog_filter_set_active(nslog_filter_t *filter, nslog_filter_t **prev)
nslog_error nslog_filter_not_new(nslog_filter_t *input, nslog_filter_t **filter)
nslog_level
Definition: nslog.h:31
@ NSLOG_LEVEL_WARNING
Definition: nslog.h:36
@ NSLOG_LEVEL_INFO
Definition: nslog.h:35
@ NSLOG_LEVEL_ERROR
Definition: nslog.h:37
@ NSLOG_LEVEL_DEBUG
Definition: nslog.h:33
@ NSLOG_LEVEL_VERBOSE
Definition: nslog.h:34
@ NSLOG_LEVEL_CRITICAL
Definition: nslog.h:38
@ NSLOG_LEVEL_DEEPDEBUG
Definition: nslog.h:32
void(* nslog_callback)(void *context, nslog_entry_context_t *ctx, const char *fmt, va_list args)
Definition: nslog.h:242
nslog_error nslog_filter_category_new(const char *catname, nslog_filter_t **filter)
char * nslog_filter_sprintf(nslog_filter_t *filter)
nslog_error nslog_filter_dirname_new(const char *dirname, nslog_filter_t **filter)
nslog_error nslog_filter_and_new(nslog_filter_t *left, nslog_filter_t *right, nslog_filter_t **filter)
const char * nslog_short_level_name(nslog_level level)
nslog_error
Definition: nslog.h:221
@ NSLOG_UNCORKED
Definition: nslog.h:224
@ NSLOG_NO_ERROR
Definition: nslog.h:222
@ NSLOG_PARSE_ERROR
Definition: nslog.h:225
@ NSLOG_NO_MEMORY
Definition: nslog.h:223
nslog_error nslog_filter_level_new(nslog_level level, nslog_filter_t **filter)
nslog_error nslog_filter_funcname_new(const char *funcname, nslog_filter_t **filter)
nslog_error nslog_uncork(void)
struct nslog_category_s nslog_category_t
void nslog__log(nslog_entry_context_t *ctx, const char *pattern,...) __attribute__((format(printf
nslog_filter_t * nslog_filter_unref(nslog_filter_t *filter)
nslog_error nslog_filter_from_text(const char *input, nslog_filter_t **output)
struct nslog_filter_s nslog_filter_t
Definition: nslog.h:302
struct nslog_category_s * next
Definition: nslog.h:98
const char * description
Definition: nslog.h:94
char * name
Definition: nslog.h:96
struct nslog_category_s * parent
Definition: nslog.h:95
const char * cat_name
Definition: nslog.h:93
Definition: nslog.h:109
const char * funcname
Definition: nslog.h:114
int funcnamelen
Definition: nslog.h:115
const char * filename
Definition: nslog.h:112
int lineno
Definition: nslog.h:116
nslog_category_t * category
Definition: nslog.h:110
int filenamelen
Definition: nslog.h:113
nslog_level level
Definition: nslog.h:111