gchar *saved_module;
gchar *saved_id;
guint saved_loglevel;
- rspamd_mempool_t *pool;
- rspamd_mempool_mutex_t *mtx;
guint64 log_cnt[4];
};
static rspamd_logger_t *default_logger = NULL;
-#define RSPAMD_LOGGER_LOCK(l) do { \
- if ((l) != NULL && !(l)->no_lock) { \
- rspamd_mempool_lock_mutex ((l)->mtx); \
- } \
-} while (0)
-
-#define RSPAMD_LOGGER_UNLOCK(l) do { \
- if ((l) != NULL && !(l)->no_lock) { \
- rspamd_mempool_unlock_mutex ((l)->mtx); \
- } \
-} while (0)
-
static void
syslog_log_function (const gchar *log_domain, const gchar *module,
const gchar *id, const gchar *function,
glong r;
if (rspamd_log->enabled) {
+ if (!rspamd_log->no_lock) {
+ rspamd_file_lock (rspamd_log->fd, FALSE);
+ }
+
if (is_iov) {
iov = (struct iovec *) data;
r = writev (rspamd_log->fd, iov, count);
line = (const gchar *) data;
r = write (rspamd_log->fd, line, count);
}
+
+ if (!rspamd_log->no_lock) {
+ rspamd_file_unlock (rspamd_log->fd, FALSE);
+ }
+
if (r == -1) {
/* We cannot write message to file, so we need to detect error and make decision */
if (errno == EINTR) {
struct rspamd_main *rspamd)
{
if (rspamd->logger == NULL) {
- rspamd->logger = g_malloc (sizeof (rspamd_logger_t));
- memset (rspamd->logger, 0, sizeof (rspamd_logger_t));
- /* Small pool for interlocking */
- rspamd->logger->pool = rspamd_mempool_new (512, NULL);
- rspamd->logger->mtx = rspamd_mempool_get_mutex (rspamd->logger->pool);
+ rspamd->logger = g_slice_alloc0 (sizeof (rspamd_logger_t));
}
rspamd->logger->type = cfg->log_type;
else {
if (rspamd_logger_need_log (rspamd_log, log_level, module)) {
rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args);
- RSPAMD_LOGGER_LOCK (rspamd_log);
rspamd_log->log_func (NULL, module, id,
function,
log_level,
logbuf,
FALSE,
rspamd_log);
- RSPAMD_LOGGER_UNLOCK (rspamd_log);
}
switch (log_level) {
}
}
- RSPAMD_LOGGER_LOCK (rspamd_log);
va_start (vp, fmt);
end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, vp);
*end = '\0';
logbuf,
TRUE,
rspamd_log);
- RSPAMD_LOGGER_UNLOCK (rspamd_log);
}
}
if (rspamd_log->enabled &&
rspamd_logger_need_log (rspamd_log, log_level, NULL)) {
- RSPAMD_LOGGER_LOCK (rspamd_log);
rspamd_log->log_func (log_domain, "glib", NULL,
NULL,
log_level,
message,
FALSE,
rspamd_log);
- RSPAMD_LOGGER_UNLOCK (rspamd_log);
}
}