changeset 12277:80097e5c38e9

log: Avoid calling time() unnecessary when logging multiple lines.
author Timo Sirainen <tss@iki.fi>
date Fri, 15 Oct 2010 16:09:13 +0100
parents e68366e88099
children 3385e9028410
files src/log/log-connection.c
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/log/log-connection.c	Fri Oct 15 16:08:12 2010 +0100
+++ b/src/log/log-connection.c	Fri Oct 15 16:09:13 2010 +0100
@@ -122,7 +122,8 @@
 	}
 }
 
-static void log_it(struct log_connection *log, const char *line)
+static void
+log_it(struct log_connection *log, const char *line, const struct tm *tm)
 {
 	struct failure_line failure;
 	struct failure_context failure_ctx;
@@ -153,6 +154,7 @@
 
 	memset(&failure_ctx, 0, sizeof(failure_ctx));
 	failure_ctx.type = failure.log_type;
+	failure_ctx.timestamp = tm;
 
 	prefix = client != NULL && client->prefix != NULL ?
 		client->prefix : log->default_prefix;
@@ -210,6 +212,9 @@
 static void log_connection_input(struct log_connection *log)
 {
 	const char *line;
+	ssize_t ret;
+	time_t now;
+	struct tm tm;
 
 	if (!log->handshaked) {
 		if (log_connection_handshake(log) < 0) {
@@ -218,8 +223,14 @@
 		}
 	}
 
-	while ((line = i_stream_read_next_line(log->input)) != NULL)
-		log_it(log, line);
+	while ((ret = i_stream_read(log->input)) > 0 || ret == -2) {
+		/* get new timestamps for every read() */
+		now = time(NULL);
+		tm = *localtime(&now);
+
+		while ((line = i_stream_next_line(log->input)) != NULL)
+			log_it(log, line, &tm);
+	}
 
 	if (log->input->eof)
 		log_connection_destroy(log);