[beast: 9/57] SFI: add current time and executable_name() prefix to debug messages



commit 430e8e0905e80c2c66397a9deab9edc96daeb583
Author: Tim Janik <timj gnu org>
Date:   Fri Jul 14 01:37:43 2017 +0200

    SFI: add current time and executable_name() prefix to debug messages
    
    Signed-off-by: Tim Janik <timj gnu org>

 sfi/bcore.cc |   12 ++++++++++++
 sfi/bcore.hh |    3 ++-
 2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/sfi/bcore.cc b/sfi/bcore.cc
index ee54e57..452b016 100644
--- a/sfi/bcore.cc
+++ b/sfi/bcore.cc
@@ -1,6 +1,8 @@
 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
 #include "bcore.hh"
+#include "platform.hh"
 #include <unistd.h>     // _exit
+#include <sys/time.h>   // gettimeofday
 
 namespace Bse {
 using namespace Rapicorn;
@@ -72,6 +74,16 @@ diagnostic (char kind, const std::string &message)
   printerr ("%s%s%s", prefix, message, newline);
 }
 
+void
+debug_diagnostic (const char *prefix, const std::string &message)
+{
+  struct timeval tv = { 0, };
+  gettimeofday (&tv, NULL);
+  const char *const newline = !message.empty() && message.data()[message.size() - 1] == '\n' ? "" : "\n";
+  const String pprefix = prefix ? prefix : executable_name();
+  printerr ("%u.%06u %s: %s%s", tv.tv_sec, tv.tv_usec, pprefix, message, newline);
+}
+
 } // Internal
 
 } // Bse
diff --git a/sfi/bcore.hh b/sfi/bcore.hh
index d34822e..3548df7 100644
--- a/sfi/bcore.hh
+++ b/sfi/bcore.hh
@@ -41,6 +41,7 @@ namespace Internal {
 extern bool                         debug_any_enabled;  //< Indicates if $BSE_DEBUG enables some debug 
settings.
 bool                                debug_key_enabled (const char *conditional) BSE_PURE;
 void                                diagnostic        (char kind, const std::string &message);
+void                                debug_diagnostic  (const char *prefix, const std::string &message);
 void                                force_abort       () RAPICORN_NORETURN;
 } // Internal
 
@@ -57,7 +58,7 @@ template<class ...Args> inline void RAPICORN_ALWAYS_INLINE
 debug (const char *conditional, const char *format, const Args &...args)
 {
   if (BSE_UNLIKELY (Internal::debug_any_enabled) && Internal::debug_key_enabled (conditional))
-    Internal::diagnostic ('D', string_format (format, args...));
+    Internal::debug_diagnostic (conditional, string_format (format, args...));
 }
 
 /// Check if @a conditional is enabled by $BSE_DEBUG.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]