diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-12-22 01:32:18 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-12-22 01:32:18 +0300 |
commit | e413f4ee9cd298baab701df31ab4c1cb91c7c4b6 (patch) | |
tree | 46858bef680c8a09b6d1d58a5ca7e3a8cec4e62d /src/logger.h | |
parent | a079dac866ac4e166a8d6e40f978af74e8398583 (diff) | |
download | rspamd-e413f4ee9cd298baab701df31ab4c1cb91c7c4b6.tar.gz rspamd-e413f4ee9cd298baab701df31ab4c1cb91c7c4b6.zip |
* Introduce new logging system:
- independent and customizeable buffering
- line buffering
- errors handling support
- custom (ip based) debug
- append function name automaticaly (based on __FUNCTION__)
- add some logic to logs system
Diffstat (limited to 'src/logger.h')
-rw-r--r-- | src/logger.h | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/logger.h b/src/logger.h new file mode 100644 index 000000000..e86901cfc --- /dev/null +++ b/src/logger.h @@ -0,0 +1,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 |