]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Rolled a basename-alike method to beautify HERE calls for debugs().
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 3 Mar 2009 13:33:51 +0000 (14:33 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 3 Mar 2009 13:33:51 +0000 (14:33 +0100)
src/Debug.h
src/debug.cc
test-suite/test_tools.cc

index f9cec79b0b8d658450e81f78fe70f3b1335b5d62..a668c9023e6a8c5374fbffd1c18f90d04551a013 100644 (file)
 #ifndef SQUID_DEBUG_H
 #define SQUID_DEBUG_H
 
-/* NP: done without pre-requisite config.h  */
-/*     because we only define with it here. */
-#if HAVE_LIBGEN_H  
-#include <libgen.h>
-#endif
-
 #include <iostream>
 #undef assert
 #include <sstream>
@@ -86,6 +80,8 @@ private:
 
 extern FILE *debug_log;
 
+SQUIDCEXTERN const char* SkipBuildPrefix(const char* path);
+
 /* Debug stream */
 #define debugs(SECTION, LEVEL, CONTENT) \
    do { \
@@ -100,7 +96,7 @@ extern FILE *debug_log;
  *
  * debugs(1,2, HERE << "some message");
  */
-#define HERE basename(__FILE__)<<"("<<__LINE__<<") "<<__FUNCTION__<<": "
+#define HERE SkipBuildPrefix(__FILE__)<<"("<<__LINE__<<") "<<__FUNCTION__<<": "
 
 /*
  * MYNAME is for use at debug levels 0 and 1 where HERE is too messy.
index 466e4820d59cc88172a8ea4faa4dfb784dc6ec03..ea02e8d4e7d5d5d61d9bc7b2a799bd4f4614f687 100644 (file)
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
  *
  */
+
+/* Anyone moving the src/Debug.cc file MUST record its new location here,
+ * or there will be issues in the debugging statements, possibly fatal!
+ */
+#define RELATIVE_PATH_TO_DEBUG_CC "src/debug.cc"
+
 #include "config.h"
 #include "Debug.h"
 #include "SquidTime.h"
@@ -746,3 +752,18 @@ Debug::xassert(const char *msg, const char *file, int line) {
 }
 
 std::ostringstream (*Debug::CurrentDebug)(NULL);
+
+static const size_t BuildPrefixInit()
+{
+    //leave immediately if misconfigured. Unfortunately not possible to detect at build
+    const char *file=__FILE__;
+    const char *rptdcc=RELATIVE_PATH_TO_DEBUG_CC;
+    assert(strstr(file,rptdcc)!=NULL);
+    return strlen(file)-strlen(rptdcc);
+}
+static const size_t BuildPrefixLength=BuildPrefixInit();
+const char* SkipBuildPrefix(const char* path)
+{
+    return path+BuildPrefixLength;
+}
+
index 02e33fb215d984aedcda70a2cb061c949f117f42..fb5748f14d189a436c581e0027dfc104992265d5 100644 (file)
@@ -234,3 +234,9 @@ ctx_enter(const char *descr) {
 
 void
 ctx_exit(Ctx ctx) {}
+
+// for debugs()
+const char* SkipBuildPrefix(const char* path)
+{
+    return path;
+}