@@ -193,6 +193,7 @@ config_logger (struct rspamd_main *rspamd, gboolean is_fatal) | |||
else { | |||
rspamd->cfg->log_fd = 2; | |||
} | |||
rspamd_set_logger (file_log_function, rspamd->cfg); | |||
g_log_set_default_handler (file_log_function, rspamd->cfg); | |||
break; | |||
case RSPAMD_LOG_FILE: | |||
@@ -206,6 +207,7 @@ config_logger (struct rspamd_main *rspamd, gboolean is_fatal) | |||
} | |||
} | |||
else { | |||
rspamd_set_logger (file_log_function, rspamd->cfg); | |||
g_log_set_default_handler (file_log_function, rspamd->cfg); | |||
} | |||
break; | |||
@@ -220,6 +222,7 @@ config_logger (struct rspamd_main *rspamd, gboolean is_fatal) | |||
} | |||
} | |||
else { | |||
rspamd_set_logger (syslog_log_function, rspamd->cfg); | |||
g_log_set_default_handler (syslog_log_function, rspamd->cfg); | |||
} | |||
break; | |||
@@ -446,6 +449,7 @@ main (int argc, char **argv, char **env) | |||
/* First set logger to console logger */ | |||
cfg->log_fd = STDERR_FILENO; | |||
rspamd_set_logger (file_log_function, rspamd->cfg); | |||
g_log_set_default_handler (file_log_function, cfg); | |||
#ifndef HAVE_SETPROCTITLE |
@@ -16,6 +16,7 @@ | |||
#include "filter.h" | |||
#include "buffer.h" | |||
#include "hash.h" | |||
#include "util.h" | |||
/* Default values */ | |||
#define FIXED_CONFIG_FILE CMAKE_PREFIX "/etc/rspamd.conf" | |||
@@ -27,10 +28,10 @@ | |||
#define WORKER_IO_TIMEOUT 60 | |||
/* Logging in postfix style */ | |||
#define msg_err g_critical | |||
#define msg_warn g_warning | |||
#define msg_info g_message | |||
#define msg_debug g_debug | |||
#define msg_err(args...) rspamd_log_function(G_LOG_LEVEL_CRITICAL, ##args) | |||
#define msg_warn(args...) rspamd_log_function(G_LOG_LEVEL_WARNING, ##args) | |||
#define msg_info(args...) rspamd_log_function(G_LOG_LEVEL_INFO, ##args) | |||
#define msg_debug(args...) rspamd_log_function(G_LOG_LEVEL_DEBUG, ##args) | |||
#ifdef CRLF | |||
#undef CRLF |
@@ -9,6 +9,9 @@ | |||
#include "config.h" | |||
#include "fuzzy.h" | |||
struct worker_task; | |||
struct controller_session; | |||
struct mime_part { | |||
GMimeContentType *type; | |||
GByteArray *content; |
@@ -40,7 +40,14 @@ struct list_file { | |||
struct stat st; | |||
}; | |||
struct logger_params { | |||
GLogFunc log_func; | |||
struct config_file *cfg; | |||
}; | |||
static GHashTable *listfiles = NULL; | |||
static struct logger_params log_params; | |||
int | |||
make_socket_nonblocking (int fd) | |||
@@ -662,6 +669,13 @@ close_log (struct config_file *cfg) | |||
} | |||
void | |||
rspamd_set_logger (GLogFunc func, struct config_file *cfg) | |||
{ | |||
log_params.log_func = func; | |||
log_params.cfg = cfg; | |||
} | |||
int | |||
reopen_log (struct config_file *cfg) | |||
{ | |||
@@ -670,6 +684,20 @@ reopen_log (struct config_file *cfg) | |||
return open_log (cfg); | |||
} | |||
void | |||
rspamd_log_function (GLogLevelFlags log_level, const char *fmt, ...) | |||
{ | |||
static char logbuf[BUFSIZ]; | |||
va_list vp; | |||
if (log_level <= log_params.cfg->log_level) { | |||
va_start (vp, fmt); | |||
vsnprintf (logbuf, sizeof (logbuf), fmt, vp); | |||
va_end (vp); | |||
log_params.log_func (NULL, log_level, logbuf, log_params.cfg); | |||
} | |||
} | |||
void | |||
syslog_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer arg) | |||
{ |
@@ -2,9 +2,11 @@ | |||
#define RSPAMD_UTIL_H | |||
#include "config.h" | |||
#include "main.h" | |||
#include "mem_pool.h" | |||
struct config_file; | |||
struct rspamd_main; | |||
struct workq; | |||
/* Create socket and bind or connect it to specified address and port */ | |||
int make_tcp_socket (struct in_addr *, u_short, gboolean is_server); | |||
@@ -47,9 +49,11 @@ int pidfile_close(struct pidfh *pfh); | |||
int pidfile_remove(struct pidfh *pfh); | |||
#endif | |||
void rspamd_set_logger (GLogFunc func, struct config_file *cfg); | |||
int open_log (struct config_file *cfg); | |||
void close_log (struct config_file *cfg); | |||
int reopen_log (struct config_file *cfg); | |||
void rspamd_log_function (GLogLevelFlags log_level, const char *fmt, ...); | |||
void syslog_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer arg); | |||
void file_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer arg); | |||