diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-08-25 16:47:55 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-08-25 16:47:55 +0400 |
commit | 52eacd589704ae63a3794a1ed111de06add196f3 (patch) | |
tree | 5cb558c529a55d2cf7d0fb34df24ecaf53192bcf | |
parent | ac9d66b9a80f49235b21de577764c5457544cc66 (diff) | |
download | rspamd-52eacd589704ae63a3794a1ed111de06add196f3.tar.gz rspamd-52eacd589704ae63a3794a1ed111de06add196f3.zip |
* Use buffered IO for logging
-rw-r--r-- | src/cfg_file.h | 1 | ||||
-rw-r--r-- | src/main.c | 5 | ||||
-rw-r--r-- | src/util.c | 20 |
3 files changed, 12 insertions, 14 deletions
diff --git a/src/cfg_file.h b/src/cfg_file.h index 44e9421b0..6529fea51 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -190,6 +190,7 @@ struct config_file { 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 */ diff --git a/src/main.c b/src/main.c index 233b93eeb..b2de3bf98 100644 --- a/src/main.c +++ b/src/main.c @@ -195,9 +195,11 @@ config_logger (struct rspamd_main *rspamd, gboolean is_fatal) 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); @@ -507,6 +509,7 @@ main (int argc, char **argv, char **env) /* 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); diff --git a/src/util.c b/src/util.c index bbe7ff666..3cd24a6eb 100644 --- a/src/util.c +++ b/src/util.c @@ -650,6 +650,7 @@ open_log (struct config_file *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; @@ -666,7 +667,9 @@ close_log (struct config_file *cfg) closelog (); break; case RSPAMD_LOG_FILE: - close (cfg->log_fd); + if (cfg->logf != NULL) { + fclose (cfg->logf); + } break; } @@ -734,12 +737,10 @@ file_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gcha { 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 @@ -752,15 +753,8 @@ file_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gcha 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); } } |