-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.h
60 lines (51 loc) · 1.53 KB
/
log.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef _LOG_H_
#define _LOG_H_
#include <stdio.h>
#include <glib.h>
/* macro to log fields in structs. */
#define log_struct(st, field, format, typecast) \
log_msg(" " #field " = " #format "\n", typecast st->field)
/* We want to use the file localized log_level whenever we call
* log_msg.
*/
typedef enum {
DEBUG,
INFO,
WARN,
ERROR,
LOG_MAX
} log_level_t;
/* Used to log at the current level (always shows up)
* should be used sparingly. debug,info,warn, or error
* should be prefered
*/
#ifdef NO_LOGGING
#define log_msg(...)
#else
#define log_msg(...) log_msg0(g_log_filtering_level, __VA_ARGS__)
#endif
#ifdef NO_LOGGING
#define delio(LEVEL,...)
#else
#define delio(LEVEL,...) log_msg1((LEVEL), __FILE__, __LINE__, __VA_ARGS__)
#endif
#define debug(...) delio(DEBUG, __VA_ARGS__)
#define info(...) delio(INFO, __VA_ARGS__)
#define warn(...) delio(WARN, __VA_ARGS__)
#define error(...) delio(ERROR, __VA_ARGS__)
void log_open(const char *name, int log_filter);
void log_open0(FILE *f, int log_filter);
void log_close();
void log_hash (GHashTable *hsh);
void log_msg0(int level, const char *format, ...);
void vlog_msg0 (int log_level, const char *format, va_list ap);
void log_msg1 (int log_level, const char *file, int line_number, const char *format, ...);
int log_error (const char *str);
void log_hash (GHashTable *hsh);
void log_list (GList *l);
void lock_log (void);
void unlock_log (void);
void set_log_filter (int filter_level);
const char *log_level_name(int i);
int g_log_filtering_level;
#endif /* _LOG_H_ */