NetSurf
log.h
Go to the documentation of this file.
1/*
2 * Copyright 2003 James Bursa <bursa@users.sourceforge.net>
3 * Copyright 2004 John Tytgat <joty@netsurf-browser.org>
4 *
5 * This file is part of NetSurf, http://www.netsurf-browser.org/
6 *
7 * NetSurf is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * NetSurf is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NETSURF_LOG_H
21#define NETSURF_LOG_H
22
23#include <stdio.h>
24#include <stdbool.h>
25
26#include "utils/errors.h"
27
28extern bool verbose_log;
29
30/**
31 * Ensures the FILE handle is available to write logging to.
32 *
33 * This is provided by the frontends if required
34 */
35typedef bool(nslog_ensure_t)(FILE *fptr);
36
37/**
38 * Initialise the logging system.
39 *
40 * Sets up everything required for logging. Processes the argv passed
41 * to remove the -v switch for verbose logging. If necessary ensures
42 * the output file handle is available.
43 */
44extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv);
45
46/**
47 * Shut down the logging system.
48 *
49 * Shuts down the logging subsystem, resetting to verbose logging and output
50 * to stderr. Note, if logging is done after calling this, it will be sent
51 * to stderr without filtering.
52 */
53extern void nslog_finalise(void);
54
55/**
56 * Set the logging filter.
57 *
58 * Compiles and enables the given logging filter.
59 */
60extern nserror nslog_set_filter(const char *filter);
61
62/**
63 * Set the logging filter according to the options.
64 */
66
67/* ensure a logging level is defined */
68#ifndef NETSURF_LOG_LEVEL
69#define NETSURF_LOG_LEVEL INFO
70#endif
71
72#define NSLOG_LVL(level) NSLOG_LEVEL_ ## level
73#define NSLOG_EVL(level) NSLOG_LVL(level)
74#define NSLOG_COMPILED_MIN_LEVEL NSLOG_EVL(NETSURF_LOG_LEVEL)
75
76#ifdef WITH_NSLOG
77
78#include <nslog/nslog.h>
79
80NSLOG_DECLARE_CATEGORY(netsurf);
81NSLOG_DECLARE_CATEGORY(llcache);
82NSLOG_DECLARE_CATEGORY(fetch);
83NSLOG_DECLARE_CATEGORY(plot);
84NSLOG_DECLARE_CATEGORY(schedule);
85NSLOG_DECLARE_CATEGORY(fbtk);
86NSLOG_DECLARE_CATEGORY(layout);
87NSLOG_DECLARE_CATEGORY(flex);
88NSLOG_DECLARE_CATEGORY(dukky);
89NSLOG_DECLARE_CATEGORY(jserrors);
90
91#else /* WITH_NSLOG */
92
102
103extern void nslog_log(const char *file, const char *func, int ln, const char *format, ...) __attribute__ ((format (printf, 4, 5)));
104
105# ifdef __GNUC__
106# define LOG_FN __PRETTY_FUNCTION__
107# define LOG_LN __LINE__
108# elif defined(__CC_NORCROFT)
109# define LOG_FN __func__
110# define LOG_LN __LINE__
111# else
112# define LOG_FN ""
113# define LOG_LN __LINE__
114# endif
115
116#define NSLOG(catname, level, logmsg, args...) \
117 do { \
118 if (NSLOG_LEVEL_##level >= NSLOG_COMPILED_MIN_LEVEL) { \
119 nslog_log(__FILE__, LOG_FN, LOG_LN, logmsg , ##args); \
120 } \
121 } while(0)
122
123#endif /* WITH_NSLOG */
124
125#endif
static const __attribute__((used))
Definition: gui.c:358
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
fbtk_widget_t * fbtk
Definition: gui.c:62
static struct llcache_s * llcache
low level cache state
Definition: llcache.c:267
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
Initialise the logging system.
Definition: log.c:190
bool verbose_log
flag to enable verbose logging
Definition: log.c:31
void nslog_log(const char *file, const char *func, int ln, const char *format,...) __attribute__((format(printf
nserror nslog_set_filter_by_options(void)
Set the logging filter according to the options.
Definition: log.c:289
nslog_level
Definition: log.h:93
@ NSLOG_LEVEL_WARNING
Definition: log.h:98
@ NSLOG_LEVEL_INFO
Definition: log.h:97
@ NSLOG_LEVEL_ERROR
Definition: log.h:99
@ NSLOG_LEVEL_DEBUG
Definition: log.h:95
@ NSLOG_LEVEL_VERBOSE
Definition: log.h:96
@ NSLOG_LEVEL_CRITICAL
Definition: log.h:100
@ NSLOG_LEVEL_DEEPDEBUG
Definition: log.h:94
bool() nslog_ensure_t(FILE *fptr)
Ensures the FILE handle is available to write logging to.
Definition: log.h:35
void nslog_finalise(void)
Shut down the logging system.
Definition: log.c:299
nserror nslog_set_filter(const char *filter)
Set the logging filter.
Definition: log.c:181
Information for a single fetch.
Definition: fetch.c:89