From 8d6e110914e4a3fa6f9091eb98d9865f48b0de95 Mon Sep 17 00:00:00 2001 From: Kalo Zsombor Date: Thu, 4 Sep 2025 23:09:11 +0200 Subject: [PATCH 1/2] logging with timestamp --- sockssrv.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sockssrv.c b/sockssrv.c index d59fc27..52fb6e0 100644 --- a/sockssrv.c +++ b/sockssrv.c @@ -35,6 +35,8 @@ #include #include "server.h" #include "sblist.h" +#include +#include /* timeout in microseconds on resource exhaustion to prevent excessive cpu usage. */ @@ -111,7 +113,20 @@ struct thread { /* we log to stderr because it's not using line buffering, i.e. malloc which would need locking when called from different threads. for the same reason we use dprintf, which writes directly to an fd. */ -#define dolog(...) do { if(!quiet) dprintf(2, __VA_ARGS__); } while(0) +static inline void dolog(const char *fmt, ...) { + char t[32] = {}; + struct tm tm_buf; + time_t secs = time(NULL); + + va_list args; + va_start(args, fmt); + + strftime(t, sizeof(t), "[%Y-%m-%d %T] ", localtime_r(&secs, &tm_buf)); + dprintf(fileno(stderr), "%s", t); + vdprintf(fileno(stderr), fmt, args); + + va_end(args); +} #else static void dolog(const char* fmt, ...) { } #endif From 0a5f9bfc206e48595e829442b1316321ba34923a Mon Sep 17 00:00:00 2001 From: Kalo Zsombor Date: Thu, 4 Sep 2025 23:48:38 +0200 Subject: [PATCH 2/2] add startup message --- sockssrv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sockssrv.c b/sockssrv.c index 52fb6e0..3193606 100644 --- a/sockssrv.c +++ b/sockssrv.c @@ -494,6 +494,7 @@ int main(int argc, char** argv) { return 1; } server = &s; + dolog("Listening on %s:%d\n", listenip, port); while(1) { collect(threads);