From 4e8e7c5330f2402b88bb0f0f8980b0105ad2241c Mon Sep 17 00:00:00 2001
From: Stuart Mark James <stuart.james@esrf.fr>
Date: Wed, 17 Jul 2019 10:16:40 +0200
Subject: [PATCH] Tango exceptions now include filename where the error is
 raised

---
 src/LibUtils.hpp              | 19 +++++++++++++++++--
 test/AttributeTraitsTests.cpp |  4 ++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/LibUtils.hpp b/src/LibUtils.hpp
index c1c560a..1fabc1b 100644
--- a/src/LibUtils.hpp
+++ b/src/LibUtils.hpp
@@ -59,7 +59,7 @@ std::ostream &operator<<(std::ostream &os, Tango::CmdArgType type);
 std::ostream &operator<<(std::ostream &os, Tango::AttrQuality quality);
 
 // SPDLOG config and setup
-const string LibLoggerName = "hdbpp_internal";
+const string LibLoggerName = "hdbpp";
 
 struct LogConfigurator
 {
@@ -68,10 +68,25 @@ struct LogConfigurator
     static void setLoggingLevel(spdlog::level::level_enum level);
 };
 
+// get the file name from the __FILE__ variable for error messages
+constexpr auto* getFileName(const char* const path)
+{
+    const auto* start_position = path;
+
+    for (const auto* current_character = path; *current_character != '\0'; ++current_character)
+        if (*current_character == '\\' || *current_character == '/')
+            start_position = current_character;
+
+    if (start_position != path)
+        ++start_position;
+
+    return start_position;
+}
+
 // Macros to get the location for reporting errors
 #define S1(x) #x
 #define S2(x) S1(x)
-#define LOCATION_INFO string(__func__) + ":" S2(__LINE__)
+#define LOCATION_INFO string(getFileName(__FILE__)) + ":" + string(__func__) + ":" S2(__LINE__)
 
 }; // namespace hdbpp_internal
 #endif // _LIBUTILS_H
diff --git a/test/AttributeTraitsTests.cpp b/test/AttributeTraitsTests.cpp
index 72a9d83..697c780 100644
--- a/test/AttributeTraitsTests.cpp
+++ b/test/AttributeTraitsTests.cpp
@@ -20,11 +20,15 @@
 #include "AttributeTraits.hpp"
 #include "catch2/catch.hpp"
 
+#include "LibUtils.hpp"
+
 using namespace std;
 using namespace hdbpp_internal;
 
 SCENARIO("Attribute format returns expected results", "[attribute-traits]")
 {
+    cout << LOCATION_INFO << endl;
+
     GIVEN("Constructed AttributeTraits as an Array")
     {
         AttributeTraits traits {Tango::READ, Tango::SPECTRUM, Tango::DEV_BOOLEAN};
-- 
GitLab