int log_level; /**< log level trigger */
char *log_file; /**< path to logfile in case of file logging */
int log_fd; /**< log descriptor in case of file logging */
+ FILE *logf;
size_t max_statfile_size; /**< maximum size for statfile */
fprintf (stderr, "Cannot log to console while daemonized, disable logging\n");
}
rspamd->cfg->log_fd = -1;
+ rspamd->cfg->logf = NULL;
}
else {
- rspamd->cfg->log_fd = 2;
+ rspamd->cfg->logf = stderr;
+ rspamd->cfg->log_fd = STDERR_FILENO;
}
rspamd_set_logger (file_log_function, rspamd->cfg);
g_log_set_default_handler (file_log_function, rspamd->cfg);
/* First set logger to console logger */
cfg->log_fd = STDERR_FILENO;
+ cfg->logf = stderr;
rspamd_set_logger (file_log_function, rspamd->cfg);
g_log_set_default_handler (file_log_function, cfg);
fprintf (stderr, "open_log: cannot open desired log file: %s, %s", cfg->log_file, strerror (errno));
return -1;
}
+ cfg->logf = fdopen (cfg->log_fd, "w");
return 0;
}
return -1;
closelog ();
break;
case RSPAMD_LOG_FILE:
- close (cfg->log_fd);
+ if (cfg->logf != NULL) {
+ fclose (cfg->logf);
+ }
break;
}
{
struct config_file *cfg = (struct config_file *)arg;
char tmpbuf[128], timebuf[32];
- int r;
- struct iovec out[3];
time_t now;
struct tm *tms;
- if (cfg->log_fd == -1) {
+ if (cfg->log_fd == -1 || cfg->logf == NULL) {
return;
}
#ifdef RSPAMD_MAIN
now = time (NULL);
tms = localtime (&now);
strftime (timebuf, sizeof (timebuf), "%b %d %H:%M:%S", tms);
- r = snprintf (tmpbuf, sizeof (tmpbuf), "#%d: %s rspamd ", (int)getpid (), timebuf);
- out[0].iov_base = tmpbuf;
- out[0].iov_len = r;
- out[1].iov_base = (char *)message;
- out[1].iov_len = strlen (message);
- out[2].iov_base = "\r\n";
- out[2].iov_len = 2;
-
- writev (cfg->log_fd, out, sizeof (out) / sizeof (out[0]));
+ snprintf (tmpbuf, sizeof (tmpbuf), "#%d: %s rspamd ", (int)getpid (), timebuf);
+ fprintf (cfg->logf, "%s%s" CRLF, tmpbuf, message);
}
}