summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--rvnit.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/rvnit.c b/rvnit.c
index 729d831..0cd8d3d 100644
--- a/rvnit.c
+++ b/rvnit.c
@@ -309,30 +309,47 @@ logger_loop(void* ignored)
 			if (!(fds[j].revents & POLLIN))
 				continue;
 
+			struct timespec now;
+			clock_gettime(CLOCK_REALTIME, &now);
+			char timestamp[32];
+			strftime(timestamp, sizeof timestamp,
+			    "%Y-%m-%dT%H:%M:%S", gmtime(&now.tv_sec));
+
 			char buf[4096];
 			ssize_t rd = read(fds[j].fd, buf, sizeof buf);
 			if (rd < 0) {
 				perror("read");
 				continue;
 			}
-			if (fds[j].fd == selflogfd[0]) {
-				printf("%s[%d]: %.*s",
-				    "rvnit",
-				    (int)getpid(),
-				    (int)rd,
-				    buf);
-				continue;
-			}
-			for (int i = 0; i < MAX_SV; i++) {
-				if (services[i].logfd[0] == fds[j].fd) {
-					printf("%s[%d]: %.*s",
-					    services[i].name,
-					    services[i].display_pid,
-					    (int)rd,
-					    buf
-						);
-					break;
+
+			char *s = buf;
+			char *e = buf + rd;
+			while (s < e) {
+				char *eol = memchr(s, '\n', e - s);
+				if (!eol)
+					eol = e;
+
+				const char *sv = "<unknown>";
+				long pid = -1;
+
+				if (fds[j].fd == selflogfd[0]) {
+					sv = "rvnit";
+					pid = getpid();
+				} else {
+					for (int i = 0; i < MAX_SV; i++) {
+						if (services[i].logfd[0] == fds[j].fd) {
+							sv = services[i].name;
+							pid = services[i].display_pid;
+							break;
+						}
+					}
 				}
+
+				printf("%s.%05ld %s[%ld]: %.*s\n",
+				    timestamp, now.tv_nsec / 10000,
+				    sv, pid, (int)(eol - s), s);
+
+				s = eol + 1;
 			}
 		}
 	}