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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#ifndef RSPAMD_LOGGER_H
#define RSPAMD_LOGGER_H
#include "config.h"
#include "cfg_file.h"
#include "radix.h"
typedef void (*rspamd_log_func_t)(const gchar * log_domain, const gchar *function,
GLogLevelFlags log_level, const gchar * message,
gboolean forced, gpointer arg);
typedef struct rspamd_logger_s {
rspamd_log_func_t log_func;
struct config_file *cfg;
struct {
uint32_t size;
uint32_t used;
u_char *buf;
} io_buf;
int fd;
gboolean is_buffered;
gboolean enabled;
enum rspamd_log_type type;
pid_t pid;
radix_tree_t *debug_ip;
} rspamd_logger_t;
/**
* Init logger
*/
void rspamd_set_logger (enum rspamd_log_type type, struct config_file *cfg);
/**
* Open log file or initialize other structures
*/
int open_log (void);
/**
* Close log file or destroy other structures
*/
void close_log (void);
/**
* Close and open log again
*/
int reopen_log (void);
/**
* Set log pid
*/
void update_log_pid (void);
/**
* Flush log buffer for some types of logging
*/
void flush_log_buf (void);
/**
* Log function that is compatible for glib messages
*/
void rspamd_glib_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer arg);
/**
* Function with variable number of arguments support
*/
void rspamd_common_log_function (GLogLevelFlags log_level, const char *function, const char *fmt, ...);
/**
* Conditional debug function
*/
void rspamd_conditional_debug (uint32_t addr, const char *function, const char *fmt, ...) ;
/* Typical functions */
/* Logging in postfix style */
#if (defined(RSPAMD_MAIN) || defined(RSPAMD_LIB))
#define msg_err(args...) rspamd_common_log_function(G_LOG_LEVEL_CRITICAL, __FUNCTION__, ##args)
#define msg_warn(args...) rspamd_common_log_function(G_LOG_LEVEL_WARNING, __FUNCTION__, ##args)
#define msg_info(args...) rspamd_common_log_function(G_LOG_LEVEL_INFO, __FUNCTION__, ##args)
#define msg_debug(args...) rspamd_common_log_function(G_LOG_LEVEL_DEBUG, __FUNCTION__, ##args)
#define debug_task(args...) rspamd_conditional_debug(task->from_addr.s_addr, __FUNCTION__, ##args)
#define debug_ip(ip, args...) rspamd_conditional_debug((ip), __FUNCTION__, ##args)
#else
#define msg_err(args...) fprintf(stderr, ##args)
#define msg_warn(args...) fprintf(stderr, ##args)
#define msg_info(args...) fprintf(stderr, ##args)
#define msg_debug(args...) fprintf(stderr, ##args)
#define debug_task(args...) fprintf(stderr, ##args)
#endif
#endif
|