On Mon, 2009-07-20 at 13:57 +0000, Simo Sorce wrote:
> 1/3: Add timestamps when the debug level is set higher then 8
> When doing some tests it may be important to have the timestamp at which
> each operation happened. add automatically a timestamp when the level is
> high enough

Some people complained on IRC about this one, and said they would prefer
to have a separate option to tell when to add a timestamp.
Attached patch that substitute 1/3

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York
>From 47962555e63dbf1d4764eb1e2b4a829e9826bcd0 Mon Sep 17 00:00:00 2001
From: Simo Sorce <sso...@redhat.com>
Date: Tue, 14 Jul 2009 17:01:26 -0400
Subject: [PATCH] Add option to add timestamps to debug output

use '--debug-timestamps' at the command line
or set 'debug-timestamps = TRUE' in the configuration file.
---
 server/monitor/monitor.c |   11 +++++++----
 server/util/debug.c      |    9 ++++++++-
 server/util/server.c     |   12 ++++++++++++
 server/util/util.h       |   15 ++++++++++++---
 4 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c
index 11c35d0..269fcbf 100644
--- a/server/monitor/monitor.c
+++ b/server/monitor/monitor.c
@@ -763,9 +763,11 @@ static int get_service_config(struct mt_ctx *ctx, const char *name,
     }
 
     if (!svc->command) {
-        svc->command = talloc_asprintf(svc, "%s/sssd_%s -d %d",
-                                       SSSD_LIBEXEC_PATH, svc->name,
-                                       debug_level);
+        svc->command = talloc_asprintf(svc, "%s/sssd_%s -d %d%s",
+                                       SSSD_LIBEXEC_PATH,
+                                       svc->name, debug_level,
+                                       (debug_timestamps?
+                                              " --debug-timestamps":""));
         if (!svc->command) {
             talloc_free(svc);
             return ENOMEM;
@@ -870,8 +872,9 @@ static int get_provider_config(struct mt_ctx *ctx, const char *name,
     /* if there are no custom commands, build a default one */
     if (!svc->command) {
         svc->command = talloc_asprintf(svc,
-                            "%s/sssd_be -d %d --provider %s --domain %s",
+                            "%s/sssd_be -d %d%s --provider %s --domain %s",
                             SSSD_LIBEXEC_PATH, debug_level,
+                            (debug_timestamps?" --debug-timestamps":""),
                             svc->provider, svc->name);
         if (!svc->command) {
             talloc_free(svc);
diff --git a/server/util/debug.c b/server/util/debug.c
index 24dcdb1..814aec1 100644
--- a/server/util/debug.c
+++ b/server/util/debug.c
@@ -7,6 +7,7 @@
 
 const char *debug_prg_name = "sssd";
 int debug_level = 0;
+int debug_timestamps = 0;
 
 void debug_fn(const char *format, ...)
 {
@@ -58,7 +59,13 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level,
     }
 
     if (loglevel <= debug_level) {
-        debug_fn("[%s] [ldb] (%d): %s\n", debug_prg_name, loglevel, message);
+        if (debug_timestamps) {
+            debug_fn("(%010ld) [%s] [ldb] (%d): %s\n",
+                     (long)time(NULL), debug_prg_name, loglevel, message);
+        } else {
+            debug_fn("[%s] [ldb] (%d): %s\n",
+                     debug_prg_name, loglevel, message);
+        }
     }
     free(message);
 }
diff --git a/server/util/server.c b/server/util/server.c
index 4dfd18e..fd6e4cd 100644
--- a/server/util/server.c
+++ b/server/util/server.c
@@ -253,6 +253,7 @@ int server_setup(const char *name, int flags,
     uint16_t stdin_event_flags;
     char *conf_db;
     int ret = EOK;
+    bool dt;
 
     debug_prg_name = strdup(name);
     if (!debug_prg_name) {
@@ -324,6 +325,17 @@ int server_setup(const char *name, int flags,
         return ret;
     }
 
+    /* same for debug timestamps */
+    dt = (debug_timestamps != 0);
+    ret = confdb_get_bool(ctx->confdb_ctx, ctx, conf_entry,
+                          "debug-timestamps", dt, &dt);
+    if (ret != EOK) {
+        DEBUG(0, ("Error reading from confdb (%d) [%s]\n",
+                  ret, strerror(ret)));
+        return ret;
+    }
+    if (dt) debug_timestamps = 1;
+
     if (flags & FLAGS_INTERACTIVE) {
         /* terminate when stdin goes away */
         stdin_event_flags = TEVENT_FD_READ;
diff --git a/server/util/util.h b/server/util/util.h
index fac3ea5..02916c1 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
+#include <time.h>
 #include "config.h"
 #include "talloc.h"
 #include "tevent.h"
@@ -15,11 +16,14 @@
 
 extern const char *debug_prg_name;
 extern int debug_level;
+extern int debug_timestamps;
 void debug_fn(const char *format, ...);
 
 #define SSSD_DEBUG_OPTS \
 		{"debug-level",	'd', POPT_ARG_INT, &debug_level, 0, \
-		 "Debug level", NULL},
+		 "Debug level", NULL}, \
+		{"debug-timestamps", 0, POPT_ARG_NONE, &debug_timestamps, 0, \
+		 "Add debug timestamps", NULL},
 
 /** \def DEBUG(level, body)
     \brief macro to generate debug messages
@@ -37,8 +41,13 @@ void debug_fn(const char *format, ...);
 */
 #define DEBUG(level, body) do { \
     if (level <= debug_level) { \
-        debug_fn("[%s] [%s] (%d): ", \
-                 debug_prg_name, __FUNCTION__, level); \
+        if (debug_timestamps) { \
+            debug_fn("(%010ld) [%s] [%s] (%d): ", \
+                     (long)time(NULL), debug_prg_name, __FUNCTION__, level); \
+        } else { \
+            debug_fn("[%s] [%s] (%d): ", \
+                     debug_prg_name, __FUNCTION__, level); \
+        } \
         debug_fn body; \
     } \
 } while(0);
-- 
1.6.2.5

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to