]> git.lyx.org Git - features.git/commitdiff
Make debug messages more readable
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 11 Jun 2012 13:03:29 +0000 (15:03 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 11 Jun 2012 13:03:29 +0000 (15:03 +0200)
Shorten the file names output by LYXERR so that they start right after /src/.

src/support/debug.cpp
src/support/debug.h

index 29a167af917418a242c46100a9926cd7e41a788b..3a6f9018feb3926549c5af73e125c406b6279d7f 100644 (file)
 
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/FileName.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
-#include "support/FileName.h"
 #include "support/ProgressInterface.h"
+#include "support/regex.h"
 
 #include <iostream>
 #include <iomanip>
@@ -197,13 +198,29 @@ void LyXErr::endl()
 }
 
 
+char const * LyXErr::stripName(char const * n)
+{
+       string const name = n;
+       // find the last occurence of /src/ in name
+       static regex re("[\\/]src[\\/]");
+       string::const_iterator const begin = name.begin();
+       string::const_iterator it = begin;
+       string::const_iterator const end = name.end();
+       smatch results;
+       while (regex_search(it, end, results, re)) {
+               it = results[0].second;
+       }
+       return n + std::distance(begin, it);
+}
+
+
 // It seems not possible to instantiate operator template out of class body
 template<class T>
 LyXErr & toStream(LyXErr & l, T t)     
 {
        if (l.enabled()){
                l.stream() << t;
-                if (l.secondEnabled()) {
+               if (l.secondEnabled()) {
                        l.secondStream() << t;
                        ProgressInterface::instance()->lyxerrFlush();
                }
index d636e4c5c32a3c4d1487a82a3a803e47be86cfd4..a883e67d74c86c69a2ce571e3a9ea46fbe9f94df 100644 (file)
@@ -171,6 +171,9 @@ public:
        /// Returns true if t is part of the current debug level
        bool debugging(Debug::Type t = Debug::ANY) const;
 
+       ///
+       static char const * stripName(char const *);
+
 private:
        /// The current debug level
        Debug::Type dt_;
@@ -208,7 +211,7 @@ extern LyXErr lyxerr;
 #      include <boost/current_function.hpp>
 #      define CURRENT_POSITION BOOST_CURRENT_FUNCTION ": "
 #else
-# define CURRENT_POSITION __FILE__ << "(" << __LINE__ << "): "
+# define CURRENT_POSITION lyx::LyXErr::stripName(__FILE__) << " (" << __LINE__ << "): "
 #endif
 
 #define LYXERR(type, msg) \