[nsd-users] Feature request: human-readable timestamps in logs

Lukas Wunner lukas at wunner.de
Thu Feb 13 12:35:22 UTC 2014


Hi,

> When reading these logs, I have to keep converting the unix timestamp to
> human-readable. Could you please get NSD to optionally log directly in
> human-readable timestamps of the form:

Attached is a small patch we use in our tailor-made NSD RPM to achieve that.
(It's not an option though.)

Kind regards,

Lukas
-------------- next part --------------
--- util.c.orig	2013-01-09 12:58:15.000000000 +0000
+++ util.c	2013-03-20 23:30:03.000000000 +0000
@@ -125,6 +125,8 @@
 	size_t length;
 	lookup_table_type *priority_info;
 	const char *priority_text = "unknown";
+	time_t now;
+	char *cnow;
 
 	assert(global_ident);
 	assert(current_log_file);
@@ -135,8 +137,10 @@
 	}
 
 	/* Bug #104, add time_t timestamp */
-	fprintf(current_log_file, "[%d] %s[%d]: %s: %s",
-		(int)time(NULL), global_ident, (int) getpid(), priority_text, message);
+	now = time(NULL);
+	cnow = ctime(&now);
+	fprintf(current_log_file, "[%.*s] %s[%d]: %s: %s",
+		strlen(cnow)-1, cnow, global_ident, (int) getpid(), priority_text, message);
 	length = strlen(message);
 	if (length == 0 || message[length - 1] != '\n') {
 		fprintf(current_log_file, "\n");


More information about the nsd-users mailing list