RSPAMD_LOG_FILE
};
+enum rspamd_log_cfg_flags {
+ RSPAMD_LOG_FLAG_DEFAULT = 0,
+ RSPAMD_LOG_FLAG_SYSTEMD = (1 << 0),
+ RSPAMD_LOG_FLAG_COLOR = (1 << 1),
+ RSPAMD_LOG_FLAG_RE_CACHE = (1 << 2),
+ RSPAMD_LOG_FLAG_USEC = (1 << 3),
+ RSPAMD_LOG_FLAG_RSPAMADM = (1 << 4),
+};
+
struct rspamd_worker_log_pipe {
gint fd;
gint type;
};
enum rspamd_log_format_flags {
- RSPAMD_LOG_FLAG_DEFAULT = 0,
- RSPAMD_LOG_FLAG_OPTIONAL = (1 << 0),
- RSPAMD_LOG_FLAG_MIME_ALTERNATIVE = (1 << 1),
- RSPAMD_LOG_FLAG_CONDITION = (1 << 2),
- RSPAMD_LOG_FLAG_SYMBOLS_SCORES = (1 << 3),
- RSPAMD_LOG_FLAG_SYMBOLS_PARAMS = (1 << 4)
+ RSPAMD_LOG_FMT_FLAG_DEFAULT = 0,
+ RSPAMD_LOG_FMT_FLAG_OPTIONAL = (1 << 0),
+ RSPAMD_LOG_FMT_FLAG_MIME_ALTERNATIVE = (1 << 1),
+ RSPAMD_LOG_FMT_FLAG_CONDITION = (1 << 2),
+ RSPAMD_LOG_FMT_FLAG_SYMBOLS_SCORES = (1 << 3),
+ RSPAMD_LOG_FMT_FLAG_SYMBOLS_PARAMS = (1 << 4)
};
struct rspamd_log_format {
GList *debug_symbols; /**< symbols to debug */
GHashTable *debug_modules; /**< logging modules to debug */
struct rspamd_cryptobox_pubkey *log_encryption_key; /**< encryption key for logs */
- gboolean log_color; /**< output colors for console output */
- gboolean log_extended; /**< log extended information */
- gboolean log_systemd; /**< special case for systemd logger */
- gboolean log_re_cache; /**< show statistics about regexps */
- gboolean log_usec; /**< log microseconds if possible */
+ guint log_flags; /**< logging flags */
guint log_error_elts; /**< number of elements in error logbuf */
guint log_error_elt_maxlen; /**< maximum size of error log element */
struct rspamd_worker_log_pipe *log_pipes;
}
}
+ /* Handle flags */
+ val = ucl_object_lookup_any (obj, "color", "log_color", NULL);
+ if (val && ucl_object_toboolean (val)) {
+ cfg->log_flags |= RSPAMD_LOG_FLAG_COLOR;
+ }
+
+ val = ucl_object_lookup_any (obj, "systemd", "log_systemd", NULL);
+ if (val && ucl_object_toboolean (val)) {
+ cfg->log_flags |= RSPAMD_LOG_FLAG_SYSTEMD;
+ }
+
+ val = ucl_object_lookup (obj, "log_re_cache");
+ if (val && ucl_object_toboolean (val)) {
+ cfg->log_flags |= RSPAMD_LOG_FLAG_RE_CACHE;
+ }
+
+ val = ucl_object_lookup_any (obj, "usec", "log_usec", NULL);
+ if (val && ucl_object_toboolean (val)) {
+ cfg->log_flags |= RSPAMD_LOG_FLAG_USEC;
+ }
+
return rspamd_rcl_section_parse_defaults (cfg, section, cfg->cfg_pool, obj,
cfg, err);
}
G_STRUCT_OFFSET (struct rspamd_config, log_urls),
0,
"Write each URL found in a message to the log file");
- rspamd_rcl_add_default_handler (sub,
- "log_re_cache",
- rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct rspamd_config, log_re_cache),
- 0,
- "Write statistics of regexp processing to log (useful for hyperscan)");
rspamd_rcl_add_default_handler (sub,
"debug_ip",
rspamd_rcl_parse_struct_ucl,
G_STRUCT_OFFSET (struct rspamd_config, debug_symbols),
0,
"Enable debug for the specified symbols");
- rspamd_rcl_add_default_handler (sub,
- "log_color",
- rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct rspamd_config, log_color),
- 0,
- "Enable colored output (for console logging)");
- rspamd_rcl_add_default_handler (sub,
- "color",
- rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct rspamd_config, log_color),
- 0,
- "Enable colored output (for console logging)");
- rspamd_rcl_add_default_handler (sub,
- "log_systemd",
- rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct rspamd_config, log_systemd),
- 0,
- "Enable systemd compatible logging");
- rspamd_rcl_add_default_handler (sub,
- "systemd",
- rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct rspamd_config, log_systemd),
- 0,
- "Enable systemd compatible logging");
rspamd_rcl_add_default_handler (sub,
"debug_modules",
rspamd_rcl_parse_struct_string_list,
G_STRUCT_OFFSET (struct rspamd_config, log_error_elt_maxlen),
RSPAMD_CL_FLAG_UINT,
"Size of each element in error log buffer (1000 by default)");
- rspamd_rcl_add_default_handler (sub,
+
+ /* Documentation only options, handled in log_handler to map flags */
+ rspamd_rcl_add_doc_by_path (cfg,
+ "logging",
+ "Enable colored output (for console logging)",
+ "log_color",
+ UCL_BOOLEAN,
+ NULL,
+ 0,
+ NULL,
+ 0);
+ rspamd_rcl_add_doc_by_path (cfg,
+ "logging",
+ "Enable systemd compatible logging",
+ "systemd",
+ UCL_BOOLEAN,
+ NULL,
+ 0,
+ NULL,
+ 0);
+ rspamd_rcl_add_doc_by_path (cfg,
+ "logging",
+ "Write statistics of regexp processing to log (useful for hyperscan)",
+ "log_re_cache",
+ UCL_BOOLEAN,
+ NULL,
+ 0,
+ NULL,
+ 0);
+ rspamd_rcl_add_doc_by_path (cfg,
+ "logging",
+ "Use microseconds resolution for timestamps",
"log_usec",
- rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct rspamd_config, log_usec),
+ UCL_BOOLEAN,
+ NULL,
0,
- "Use microseconds resolution for timestamps");
+ NULL,
+ 0);
/**
* Options section
*/
u_char *buf;
} io_buf;
gint fd;
+ guint flags;
gboolean is_buffered;
gboolean enabled;
gboolean is_debug;
}
logger->cfg = cfg;
+ logger->flags = cfg->log_flags;
/* Set up buffer */
if (cfg->log_buffered) {
const gchar *message,
gpointer arg)
{
- gchar tmpbuf[256], timebuf[64], modulebuf[64];
+ static gchar tmpbuf[256], timebuf[64], modulebuf[64];
gchar *m;
gdouble now;
struct tm *tms;
return;
}
}
- /* Check repeats */
- mlen = strlen (message);
- cksum = rspamd_log_calculate_cksum (message, mlen);
-
- if (cksum == rspamd_log->last_line_cksum) {
- rspamd_log->repeats++;
- if (rspamd_log->repeats > REPEATS_MIN && rspamd_log->repeats <
- REPEATS_MAX) {
- /* Do not log anything */
- if (rspamd_log->saved_message == NULL) {
- rspamd_log->saved_message = g_strdup (message);
- rspamd_log->saved_function = g_strdup (function);
-
- if (module) {
- rspamd_log->saved_module = g_strdup (module);
- }
- if (id) {
- rspamd_log->saved_id = g_strdup (id);
+ if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_RSPAMADM)) {
+ /* Check repeats */
+ mlen = strlen (message);
+ cksum = rspamd_log_calculate_cksum (message, mlen);
+
+ if (cksum == rspamd_log->last_line_cksum) {
+ rspamd_log->repeats++;
+ if (rspamd_log->repeats > REPEATS_MIN && rspamd_log->repeats <
+ REPEATS_MAX) {
+ /* Do not log anything */
+ if (rspamd_log->saved_message == NULL) {
+ rspamd_log->saved_message = g_strdup (message);
+ rspamd_log->saved_function = g_strdup (function);
+
+ if (module) {
+ rspamd_log->saved_module = g_strdup (module);
+ }
+
+ if (id) {
+ rspamd_log->saved_id = g_strdup (id);
+ }
+
+ rspamd_log->saved_loglevel = level_flags;
}
- rspamd_log->saved_loglevel = level_flags;
+ return;
}
+ else if (rspamd_log->repeats > REPEATS_MAX) {
+ rspamd_snprintf (tmpbuf,
+ sizeof (tmpbuf),
+ "Last message repeated %ud times",
+ rspamd_log->repeats);
+ 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 (rspamd_log->saved_module,
+ rspamd_log->saved_id,
+ rspamd_log->saved_function,
+ rspamd_log->saved_loglevel,
+ rspamd_log->saved_message,
+ arg);
- return;
- }
- else if (rspamd_log->repeats > REPEATS_MAX) {
- rspamd_snprintf (tmpbuf,
- sizeof (tmpbuf),
- "Last message repeated %ud times",
- rspamd_log->repeats);
- 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 (rspamd_log->saved_module,
- rspamd_log->saved_id,
- rspamd_log->saved_function,
- rspamd_log->saved_loglevel,
- rspamd_log->saved_message,
- arg);
-
- g_free (rspamd_log->saved_message);
- g_free (rspamd_log->saved_function);
- g_free (rspamd_log->saved_module);
- g_free (rspamd_log->saved_id);
- rspamd_log->saved_message = NULL;
- rspamd_log->saved_function = NULL;
- rspamd_log->saved_module = NULL;
- rspamd_log->saved_id = NULL;
- }
+ g_free (rspamd_log->saved_message);
+ g_free (rspamd_log->saved_function);
+ g_free (rspamd_log->saved_module);
+ g_free (rspamd_log->saved_id);
+ rspamd_log->saved_message = NULL;
+ rspamd_log->saved_function = NULL;
+ rspamd_log->saved_module = NULL;
+ rspamd_log->saved_id = NULL;
+ }
- file_log_function ("logger", NULL,
- G_STRFUNC,
- rspamd_log->saved_loglevel,
- tmpbuf,
- arg);
- file_log_function (module, id,
- function,
- level_flags,
- message,
- arg);
- rspamd_log->repeats = REPEATS_MIN + 1;
- return;
- }
- }
- else {
- /* Reset counter if new message differs from saved message */
- rspamd_log->last_line_cksum = cksum;
- if (rspamd_log->repeats > REPEATS_MIN) {
- rspamd_snprintf (tmpbuf,
- sizeof (tmpbuf),
- "Last message repeated %ud times",
- rspamd_log->repeats);
- rspamd_log->repeats = 0;
- if (rspamd_log->saved_message) {
- file_log_function (rspamd_log->saved_module,
- rspamd_log->saved_id,
- rspamd_log->saved_function,
+ file_log_function ("logger", NULL,
+ G_STRFUNC,
rspamd_log->saved_loglevel,
- rspamd_log->saved_message,
+ tmpbuf,
arg);
-
- g_free (rspamd_log->saved_message);
- g_free (rspamd_log->saved_function);
- g_free (rspamd_log->saved_module);
- g_free (rspamd_log->saved_id);
- rspamd_log->saved_message = NULL;
- rspamd_log->saved_function = NULL;
- rspamd_log->saved_module = NULL;
- rspamd_log->saved_id = NULL;
+ file_log_function (module, id,
+ function,
+ level_flags,
+ message,
+ arg);
+ rspamd_log->repeats = REPEATS_MIN + 1;
+ return;
}
-
- file_log_function ("logger", NULL,
- G_STRFUNC,
- level_flags,
- tmpbuf,
- arg);
- /* It is safe to use temporary buffer here as it is not static */
- file_log_function (module, id,
- function,
- level_flags,
- message,
- arg);
- return;
}
else {
- rspamd_log->repeats = 0;
- }
- }
+ /* Reset counter if new message differs from saved message */
+ rspamd_log->last_line_cksum = cksum;
+ if (rspamd_log->repeats > REPEATS_MIN) {
+ rspamd_snprintf (tmpbuf,
+ sizeof (tmpbuf),
+ "Last message repeated %ud times",
+ rspamd_log->repeats);
+ rspamd_log->repeats = 0;
+ if (rspamd_log->saved_message) {
+ file_log_function (rspamd_log->saved_module,
+ rspamd_log->saved_id,
+ rspamd_log->saved_function,
+ rspamd_log->saved_loglevel,
+ rspamd_log->saved_message,
+ arg);
- if (rspamd_log->cfg->log_extended) {
+ g_free (rspamd_log->saved_message);
+ g_free (rspamd_log->saved_function);
+ g_free (rspamd_log->saved_module);
+ g_free (rspamd_log->saved_id);
+ rspamd_log->saved_message = NULL;
+ rspamd_log->saved_function = NULL;
+ rspamd_log->saved_module = NULL;
+ rspamd_log->saved_id = NULL;
+ }
+
+ file_log_function ("logger", NULL,
+ G_STRFUNC,
+ level_flags,
+ tmpbuf,
+ arg);
+ /* It is safe to use temporary buffer here as it is not static */
+ file_log_function (module, id,
+ function,
+ level_flags,
+ message,
+ arg);
+ return;
+ }
+ else {
+ rspamd_log->repeats = 0;
+ }
+ }
if (!got_time) {
now = rspamd_get_calendar_ticks ();
}
/* Format time */
- if (!rspamd_log->cfg->log_systemd) {
+ if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_SYSTEMD)) {
time_t sec = now;
gsize r;
tms = localtime (&sec);
r = strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", tms);
- if (rspamd_log->cfg->log_usec) {
+ if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) {
gchar usec_buf[16];
rspamd_snprintf (usec_buf, sizeof (usec_buf), "%.5f",
cptype = g_quark_to_string (rspamd_log->process_type);
- if (rspamd_log->cfg->log_color) {
+ if (rspamd_log->flags & RSPAMD_LOG_FLAG_COLOR) {
if (level_flags & G_LOG_LEVEL_INFO) {
/* White */
r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[0;37m");
r = 0;
}
- if (!rspamd_log->cfg->log_systemd) {
+ if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_SYSTEMD)) {
r += rspamd_snprintf (tmpbuf + r,
sizeof (tmpbuf) - r,
"%s #%P(%s) ",
iov[3].iov_base = (void *) &lf_chr;
iov[3].iov_len = 1;
- if (rspamd_log->cfg->log_color) {
+ if (rspamd_log->flags & RSPAMD_LOG_FLAG_COLOR) {
iov[4].iov_base = "\033[0m";
iov[4].iov_len = sizeof ("\033[0m") - 1;
/* Call helper (for buffering) */
}
}
else {
- iov[0].iov_base = (void *) message;
- iov[0].iov_len = mlen;
- iov[1].iov_base = (void *) &lf_chr;
- iov[1].iov_len = 1;
- if (rspamd_log->cfg->log_color) {
- iov[2].iov_base = "\033[0m";
- iov[2].iov_len = sizeof ("\033[0m") - 1;
+ /* Rspamadm logging version */
+ mlen = strlen (message);
+
+ if (rspamd_log->flags & RSPAMD_LOG_FLAG_COLOR) {
+ if (level_flags & G_LOG_LEVEL_INFO) {
+ /* White */
+ r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[0;37m");
+ }
+ else if (level_flags & G_LOG_LEVEL_WARNING) {
+ /* Magenta */
+ r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[0;32m");
+ }
+ else if (level_flags & G_LOG_LEVEL_CRITICAL) {
+ /* Red */
+ r = rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "\033[1;31m");
+ }
+
+ iov[0].iov_base = (void *) tmpbuf;
+ iov[0].iov_len = r;
+ iov[1].iov_base = (void *) message;
+ iov[1].iov_len = mlen;
+ r = 2;
+ }
+ else {
+ iov[0].iov_base = (void *) message;
+ iov[0].iov_len = mlen;
+ r = 1;
+ }
+
+
+ iov[r++].iov_base = (void *) &lf_chr;
+ iov[r++].iov_len = 1;
+
+ if (rspamd_log->flags & RSPAMD_LOG_FLAG_COLOR) {
+ iov[r++].iov_base = "\033[0m";
+ iov[r++].iov_len = sizeof ("\033[0m") - 1;
/* Call helper (for buffering) */
- file_log_helper (rspamd_log, iov, 3);
+ file_log_helper (rspamd_log, iov, r);
}
else {
/* Call helper (for buffering) */
- file_log_helper (rspamd_log, iov, 2);
+ file_log_helper (rspamd_log, iov, r);
}
}
}