+0100 From: Daniel Schall <tinc-devel at mon-clan.de> Date: Mon, 3 Jan 2011 21:04:17 +0100 Subject: [PATCH] Console Logging showing user-readable datetime Logging using flags instead of counters diff --git a/src/logger.c b/src/logger.c index bc20438..5312ef5 100644 --- a/src/logger.c +++ b/src/logger.c @@ -69,14 +69,23 @@ =20 va_start(ap, format); =20 + time_t t =3D time(NULL); + char time[32]; + char* time1 =3D asctime(localtime(&t)); + strncpy(time, time1, 26); + char* newline =3D strchr(time, '\n'); + if(newline) + *newline =3D '\0'; + switch(logmode) { case LOGMODE_STDERR: + fprintf(stderr, "%s%s ", time, ":"); vfprintf(stderr, format, ap); fprintf(stderr, "\n"); fflush(stderr); break; case LOGMODE_FILE: - fprintf(logfile, "%ld %s[%ld]: ", time(NULL), logident, (long)logpid); + fprintf(logfile, "%s %s[%ld]: ", time, logident, (long)logpid); vfprintf(logfile, format, ap); fprintf(logfile, "\n"); fflush(logfile); diff --git a/src/logger.h b/src/logger.h index 9c20ead..37cbac6 100644 --- a/src/logger.h +++ b/src/logger.h @@ -7,11 +7,11 @@ DEBUG_CONNECTIONS =3D 1, /* Show (dis)connects of other tinc daemons via TCP */ DEBUG_ERROR =3D 2, /* Show error messages received from other hosts */ DEBUG_STATUS =3D 2, /* Show status messages received from other hosts */ - DEBUG_PROTOCOL =3D 3, /* Show the requests that are sent/received */ - DEBUG_META =3D 4, /* Show contents of every request that is sent/received */ - DEBUG_TRAFFIC =3D 5, /* Show network traffic information */ - DEBUG_PACKET =3D 6, /* Show contents of each packet that is being sent/received */ - DEBUG_SCARY_THINGS =3D 10 /* You have been warned */ + DEBUG_PROTOCOL =3D 4, /* Show the requests that are sent/received */ + DEBUG_META =3D 8, /* Show contents of every request that is sent/received */ + DEBUG_TRAFFIC =3D 16, /* Show network traffic information */ + DEBUG_PACKET =3D 32, /* Show contents of each packet that is being sent/received */ + DEBUG_SCARY_THINGS =3D 64 - 1 /* You have been warned */ } debug_t; =20 typedef enum logmode_t { @@ -50,6 +50,6 @@ extern void logger(int, const char *, ...) __attribute__ ((__format__(printf, 2, 3))); extern void closelogger(void); =20 -#define ifdebug(l) if(debug_level >=3D DEBUG_##l) +#define ifdebug(l) if(debug_level & DEBUG_##l) =20 #endif /* __TINC_LOGGER_H__ */ ------=_NextPart_000_0001_01CBAE62.CE89B370--