static rspamd_logger_t *default_logger = NULL;
-static void
- syslog_log_function (const gchar *log_domain, const gchar *module,
+static void syslog_log_function (const gchar *module,
const gchar *id, const gchar *function,
- GLogLevelFlags log_level, const gchar *message,
- gboolean forced, gpointer arg);
+ gint log_level, const gchar *message,
+ gpointer arg);
static void
- file_log_function (const gchar *log_domain, const gchar *module,
+ file_log_function (const gchar *module,
const gchar *id, const gchar *function,
- GLogLevelFlags log_level, const gchar *message,
- gboolean forced, gpointer arg);
+ gint log_level, const gchar *message,
+ gpointer arg);
/**
* Calculate checksum for log line (used for repeating logic)
rspamd_log->repeats);
rspamd_log->repeats = 0;
if (rspamd_log->saved_message) {
- file_log_function (NULL,
- rspamd_log->saved_module,
+ file_log_function (rspamd_log->saved_module,
rspamd_log->saved_id,
rspamd_log->saved_function,
- rspamd_log->saved_loglevel,
+ rspamd_log->saved_loglevel | RSPAMD_LOG_FORCED,
rspamd_log->saved_message,
- TRUE,
rspamd_log);
g_free (rspamd_log->saved_message);
rspamd_log->saved_id = NULL;
}
/* It is safe to use temporary buffer here as it is not static */
- file_log_function (NULL, NULL, NULL,
+ file_log_function (NULL, NULL,
G_STRFUNC,
- rspamd_log->saved_loglevel,
+ rspamd_log->saved_loglevel | RSPAMD_LOG_FORCED,
tmpbuf,
- TRUE,
rspamd_log);
return;
}
}
void
-rspamd_common_logv (rspamd_logger_t *rspamd_log, GLogLevelFlags log_level,
+rspamd_common_logv (rspamd_logger_t *rspamd_log, gint level_flags,
const gchar *module, const gchar *id, const gchar *function,
const gchar *fmt, va_list args)
{
gchar logbuf[RSPAMD_LOGBUF_SIZE];
+ gint level = level_flags & (RSPAMD_LOG_LEVEL_MASK|G_LOG_LEVEL_MASK);
if (rspamd_log == NULL) {
rspamd_log = default_logger;
if (rspamd_log == NULL) {
/* Just fprintf message to stderr */
- if (log_level >= G_LOG_LEVEL_INFO) {
+ if (level >= G_LOG_LEVEL_INFO) {
rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args);
fprintf (stderr, "%s\n", logbuf);
}
}
else {
- if (rspamd_logger_need_log (rspamd_log, log_level, module)) {
+ if (rspamd_logger_need_log (rspamd_log, level, module)) {
rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args);
- rspamd_log->log_func (NULL, module, id,
+ rspamd_log->log_func (module, id,
function,
- log_level,
+ level_flags,
logbuf,
- FALSE,
rspamd_log);
- }
- switch (log_level) {
- case G_LOG_LEVEL_CRITICAL:
- rspamd_log->log_cnt[0] ++;
- break;
- case G_LOG_LEVEL_WARNING:
- rspamd_log->log_cnt[1]++;
- break;
- case G_LOG_LEVEL_INFO:
- rspamd_log->log_cnt[2]++;
- break;
- case G_LOG_LEVEL_DEBUG:
- rspamd_log->log_cnt[3]++;
- break;
- default:
- break;
+ switch (level) {
+ case G_LOG_LEVEL_CRITICAL:
+ rspamd_log->log_cnt[0] ++;
+ break;
+ case G_LOG_LEVEL_WARNING:
+ rspamd_log->log_cnt[1]++;
+ break;
+ case G_LOG_LEVEL_INFO:
+ rspamd_log->log_cnt[2]++;
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ rspamd_log->log_cnt[3]++;
+ break;
+ default:
+ break;
+ }
}
}
}
*/
void
rspamd_common_log_function (rspamd_logger_t *rspamd_log,
- GLogLevelFlags log_level,
+ gint level_flags,
const gchar *module, const gchar *id,
const gchar *function,
const gchar *fmt,
va_list vp;
va_start (vp, fmt);
- rspamd_common_logv (rspamd_log, log_level, module, id, function, fmt, vp);
+ rspamd_common_logv (rspamd_log, level_flags, module, id, function, fmt, vp);
va_end (vp);
}
void
-rspamd_default_logv (GLogLevelFlags log_level, const gchar *module, const gchar *id,
+rspamd_default_logv (gint level_flags, const gchar *module, const gchar *id,
const gchar *function,
const gchar *fmt, va_list args)
{
- rspamd_common_logv (NULL, log_level, module, id, function, fmt, args);
+ rspamd_common_logv (NULL, level_flags, module, id, function, fmt, args);
}
void
-rspamd_default_log_function (GLogLevelFlags log_level,
+rspamd_default_log_function (gint level_flags,
const gchar *module, const gchar *id,
const gchar *function, const gchar *fmt, ...)
{
va_list vp;
va_start (vp, fmt);
- rspamd_default_logv (log_level, module, id, function, fmt, vp);
+ rspamd_default_logv (level_flags, module, id, function, fmt, vp);
va_end (vp);
}
* Syslog interface for logging
*/
static void
-syslog_log_function (const gchar *log_domain,
- const gchar *module, const gchar *id,
+syslog_log_function (const gchar *module, const gchar *id,
const gchar *function,
- GLogLevelFlags log_level,
+ gint level_flags,
const gchar *message,
- gboolean forced,
gpointer arg)
{
rspamd_logger_t *rspamd_log = arg;
syslog_level = LOG_DEBUG;
for (i = 0; i < G_N_ELEMENTS (levels_match); i ++) {
- if (log_level & levels_match[i].glib_level) {
+ if (level_flags & levels_match[i].glib_level) {
syslog_level = levels_match[i].syslog_level;
break;
}
* Main file interface for logging
*/
static void
-file_log_function (const gchar *log_domain,
- const gchar *module, const gchar *id,
+file_log_function (const gchar *module, const gchar *id,
const gchar *function,
- GLogLevelFlags log_level,
+ gint level_flags,
const gchar *message,
- gboolean forced,
gpointer arg)
{
gchar tmpbuf[256], timebuf[32], modulebuf[64];
rspamd_log->saved_id = g_strdup (id);
}
- rspamd_log->saved_loglevel = log_level;
+ rspamd_log->saved_loglevel = level_flags;
}
return;
rspamd_log->repeats = 0;
/* It is safe to use temporary buffer here as it is not static */
if (rspamd_log->saved_message) {
- file_log_function (log_domain,
- rspamd_log->saved_module,
+ file_log_function (rspamd_log->saved_module,
rspamd_log->saved_id,
rspamd_log->saved_function,
rspamd_log->saved_loglevel,
rspamd_log->saved_message,
- forced,
arg);
g_free (rspamd_log->saved_message);
rspamd_log->saved_module = NULL;
rspamd_log->saved_id = NULL;
}
- file_log_function (log_domain, "logger", NULL,
+
+ file_log_function ("logger", NULL,
G_STRFUNC,
rspamd_log->saved_loglevel,
tmpbuf,
- forced,
arg);
- file_log_function (log_domain,
- module, id,
+ file_log_function (module, id,
function,
- log_level,
+ level_flags,
message,
- forced,
arg);
rspamd_log->repeats = REPEATS_MIN + 1;
return;
rspamd_log->repeats);
rspamd_log->repeats = 0;
if (rspamd_log->saved_message) {
- file_log_function (log_domain,
- rspamd_log->saved_module,
+ file_log_function (rspamd_log->saved_module,
rspamd_log->saved_id,
rspamd_log->saved_function,
rspamd_log->saved_loglevel,
rspamd_log->saved_message,
- forced,
arg);
g_free (rspamd_log->saved_message);
rspamd_log->saved_id = NULL;
}
- file_log_function (log_domain,
- "logger", NULL,
+ file_log_function ("logger", NULL,
G_STRFUNC,
- log_level,
+ level_flags,
tmpbuf,
- forced,
arg);
/* It is safe to use temporary buffer here as it is not static */
- file_log_function (log_domain,
- module, id,
+ file_log_function (module, id,
function,
- log_level,
+ level_flags,
message,
- forced,
arg);
return;
}
cptype = g_quark_to_string (rspamd_log->process_type);
if (rspamd_log->cfg->log_color) {
- if (log_level & G_LOG_LEVEL_INFO) {
+ if (level_flags & G_LOG_LEVEL_INFO) {
/* White */
r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[0;37m");
}
- else if (log_level & G_LOG_LEVEL_WARNING) {
+ else if (level_flags & G_LOG_LEVEL_WARNING) {
/* Magenta */
r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[0;32m");
}
- else if (log_level & G_LOG_LEVEL_CRITICAL) {
+ else if (level_flags & G_LOG_LEVEL_CRITICAL) {
/* Red */
r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[1;31m");
}
end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, vp);
*end = '\0';
va_end (vp);
- rspamd_log->log_func (NULL, module, id,
+ rspamd_log->log_func (module, id,
function,
- G_LOG_LEVEL_DEBUG,
+ G_LOG_LEVEL_DEBUG | RSPAMD_LOG_FORCED,
logbuf,
- TRUE,
rspamd_log);
}
}
if (rspamd_log->enabled &&
rspamd_logger_need_log (rspamd_log, log_level, NULL)) {
- rspamd_log->log_func (log_domain, "glib", NULL,
+ rspamd_log->log_func ("glib", NULL,
NULL,
log_level,
message,
- FALSE,
rspamd_log);
}
}
#include "radix.h"
#include "util.h"
+#ifndef G_LOG_LEVEL_USER_SHIFT
+#define G_LOG_LEVEL_USER_SHIFT 8
+#endif
-typedef void (*rspamd_log_func_t) (const gchar *log_domain,
- const gchar *module, const gchar *id, const gchar *function,
- GLogLevelFlags log_level, const gchar *message,
- gboolean forced, gpointer arg);
+enum rspamd_log_flags {
+ RSPAMD_LOG_FORCED = (1 << G_LOG_LEVEL_USER_SHIFT),
+ RSPAMD_LOG_ENCRYPTED = (1 << (G_LOG_LEVEL_USER_SHIFT + 1)),
+ RSPAMD_LOG_LEVEL_MASK = ~(RSPAMD_LOG_FORCED|RSPAMD_LOG_ENCRYPTED)
+};
+
+typedef void (*rspamd_log_func_t) (const gchar *module, const gchar *id,
+ const gchar *function,
+ gint level_flags, const gchar *message, gpointer arg);
typedef struct rspamd_logger_s rspamd_logger_t;
* Function with variable number of arguments support
*/
void rspamd_common_log_function (rspamd_logger_t *logger,
- GLogLevelFlags log_level,
+ gint level_flags,
const gchar *module, const gchar *id,
const gchar *function, const gchar *fmt, ...);
-void rspamd_common_logv (rspamd_logger_t *logger, GLogLevelFlags log_level,
+void rspamd_common_logv (rspamd_logger_t *logger, gint level_flags,
const gchar *module, const gchar *id, const gchar *function,
const gchar *fmt, va_list args);
/**
* Function with variable number of arguments support that uses static default logger
*/
-void rspamd_default_log_function (GLogLevelFlags log_level,
+void rspamd_default_log_function (gint level_flags,
const gchar *module, const gchar *id,
const gchar *function,
const gchar *fmt,
* @param fmt
* @param args
*/
-void rspamd_default_logv (GLogLevelFlags log_level,
+void rspamd_default_logv (gint level_flags,
const gchar *module, const gchar *id,
const gchar *function,
const gchar *fmt,