}
}
+static void
+rspamd_escape_log_string (gchar *str)
+{
+ guchar *p = (guchar *)str;
+
+ while (*p) {
+ if ((*p & 0x80) || !g_ascii_isprint (*p)) {
+ *p = '?';
+ }
+ else if (*p == '\n' || *p == '\r') {
+ *p = ' ';
+ }
+ p ++;
+ }
+}
+
/* Logging utility functions */
gint
open_log_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
rspamd_common_log_function (rspamd_logger_t *rspamd_log, GLogLevelFlags log_level,
const gchar *function, const gchar *fmt, ...)
{
- static gchar logbuf[BUFSIZ], escaped_logbuf[BUFSIZ];
+ static gchar logbuf[BUFSIZ];
va_list vp;
u_char *end;
va_start (vp, fmt);
end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, vp);
*end = '\0';
- (void)rspamd_escape_string (escaped_logbuf, logbuf, sizeof (escaped_logbuf));
+ rspamd_escape_log_string (logbuf);
va_end (vp);
- rspamd_log->log_func (NULL, function, log_level, escaped_logbuf, FALSE, rspamd_log);
+ rspamd_log->log_func (NULL, function, log_level, logbuf, FALSE, rspamd_log);
g_mutex_unlock (rspamd_log->mtx);
}
}
rspamd_default_log_function (GLogLevelFlags log_level,
const gchar *function, const gchar *fmt, ...)
{
- static gchar logbuf[BUFSIZ], escaped_logbuf[BUFSIZ];
+ static gchar logbuf[BUFSIZ];
va_list vp;
u_char *end;
va_start (vp, fmt);
end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, vp);
*end = '\0';
- (void)rspamd_escape_string (escaped_logbuf, logbuf, sizeof (escaped_logbuf));
+ rspamd_escape_log_string (logbuf);
va_end (vp);
- fprintf (stderr, "%s\n", escaped_logbuf);
+ fprintf (stderr, "%s\n", logbuf);
}
}
else if (log_level <= default_logger->cfg->log_level) {
va_start (vp, fmt);
end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, vp);
*end = '\0';
- (void)rspamd_escape_string (escaped_logbuf, logbuf, sizeof (escaped_logbuf));
+ rspamd_escape_log_string (logbuf);
va_end (vp);
- default_logger->log_func (NULL, function, log_level, escaped_logbuf, FALSE, default_logger);
+ default_logger->log_func (NULL, function, log_level, logbuf, FALSE, default_logger);
g_mutex_unlock (default_logger->mtx);
}
}
void
rspamd_conditional_debug (rspamd_logger_t *rspamd_log, guint32 addr, const gchar *function, const gchar *fmt, ...)
{
- static gchar logbuf[BUFSIZ], escaped_logbuf[BUFSIZ];
+ static gchar logbuf[BUFSIZ];
va_list vp;
u_char *end;
va_start (vp, fmt);
end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, vp);
*end = '\0';
- (void)rspamd_escape_string (escaped_logbuf, logbuf, sizeof (escaped_logbuf));
+ rspamd_escape_log_string (logbuf);
va_end (vp);
- rspamd_log->log_func (NULL, function, G_LOG_LEVEL_DEBUG, escaped_logbuf, TRUE, rspamd_log);
+ rspamd_log->log_func (NULL, function, G_LOG_LEVEL_DEBUG, logbuf, TRUE, rspamd_log);
g_mutex_unlock (rspamd_log->mtx);
}
}
void
rspamd_glib_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer arg)
{
- gchar escaped_logbuf[BUFSIZ];
rspamd_logger_t *rspamd_log = arg;
if (rspamd_log->enabled) {
g_mutex_lock (rspamd_log->mtx);
- (void)rspamd_escape_string (escaped_logbuf, message, sizeof (escaped_logbuf));
- rspamd_log->log_func (log_domain, NULL, log_level, escaped_logbuf, FALSE, rspamd_log);
+ rspamd_log->log_func (log_domain, NULL, log_level, message, FALSE, rspamd_log);
g_mutex_unlock (rspamd_log->mtx);
}
}