summaryrefslogtreecommitdiffstats
path: root/proxy/src/gp_debug.c
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-11-10 22:59:05 -0500
committerRobbie Harwood <rharwood@redhat.com>2015-12-01 17:33:42 -0500
commit71d316dfc51bcb9e18da61fb7299bb021523cde4 (patch)
treeac4046a1df6db33c293beee31c0fe190ddb2ab85 /proxy/src/gp_debug.c
parent0577e929ef896944b2f852f0c3071684e9b282aa (diff)
downloadgss-proxy-71d316dfc51bcb9e18da61fb7299bb021523cde4.tar.gz
gss-proxy-71d316dfc51bcb9e18da61fb7299bb021523cde4.tar.xz
gss-proxy-71d316dfc51bcb9e18da61fb7299bb021523cde4.zip
Add options to specify a debug level
Print only messages that are at that level or lower. Also add timestamps to debug messages. Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Robbie Harwood <rharwood@redhat.com>
Diffstat (limited to 'proxy/src/gp_debug.c')
-rw-r--r--proxy/src/gp_debug.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/proxy/src/gp_debug.c b/proxy/src/gp_debug.c
index f047e0d..4a1a26c 100644
--- a/proxy/src/gp_debug.c
+++ b/proxy/src/gp_debug.c
@@ -7,10 +7,11 @@
/* global debug switch */
int gp_debug;
-void gp_debug_enable(void)
+void gp_debug_enable(int level)
{
- gp_debug = 1;
- GPDEBUG("Debug Enabled\n");
+ if (level == 0) level = 1;
+ gp_debug = level;
+ GPDEBUG("Debug Enabled (level: %d)\n", level);
}
void gp_log_failure(gss_OID mech, uint32_t maj, uint32_t min)
@@ -21,3 +22,38 @@ void gp_log_failure(gss_OID mech, uint32_t maj, uint32_t min)
fprintf(stderr, "Failed with: %s\n", buf);
}
+
+const char *gp_debug_timestamp(void)
+{
+ static __thread char buffer[24];
+ static __thread time_t timestamp = 0;
+ struct tm tm_info;
+ time_t now;
+
+ time(&now);
+ if (now == timestamp) return buffer;
+
+ gmtime_r(&now, &tm_info);
+ strftime(buffer, 24, "[%Y/%m/%d %H:%M:%S]: ", &tm_info);
+ timestamp = now;
+ return buffer;
+}
+
+void gp_debug_printf(const char *format, ...)
+{
+ va_list varargs;
+ va_start(varargs, format);
+ vfprintf(stderr, format, varargs);
+ va_end(varargs);
+}
+
+void gp_debug_time_printf(const char *format, ...)
+{
+ va_list varargs;
+
+ fprintf(stderr, "%s", gp_debug_timestamp());
+
+ va_start(varargs, format);
+ vfprintf(stderr, format, varargs);
+ va_end(varargs);
+}