From c910209d51346f49603855ca1a9cdd46303a4a5a Mon Sep 17 00:00:00 2001
From: joanvallve <jvallve@iri.upc.edu>
Date: Wed, 19 Jun 2024 15:50:26 +0200
Subject: [PATCH] logging with colors

---
 include/core/utils/logging.h |  8 ++++----
 test/gtest_logging.cpp       | 10 ++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/core/utils/logging.h b/include/core/utils/logging.h
index 9c94909e2..1fac84152 100644
--- a/include/core/utils/logging.h
+++ b/include/core/utils/logging.h
@@ -135,13 +135,13 @@ inline Logger::Logger(const std::string& name) :
     //set_pattern("[%t][%H:%M:%S.%F][%l] %v");
     // [log type][MM/DD/YY - hour:minutes:seconds.nanoseconds] #log-content
 //    set_pattern("[%l][%x - %H:%M:%S.%F] %v");
-      set_pattern("[%l][%H:%M:%S] %v");
+      set_pattern("%^[%l][%H:%M:%S] %v%$");
   else
     // Logging pattern is :
     // [logger name][thread num][hour:minutes:seconds.nanoseconds][log type] #log-content
     //set_pattern("[" + log_name_ + "]" +"[%t][%H:%M:%S.%F][%l] %v");
     // [log type][MM/DD/YY - hour:minutes:seconds.nanoseconds][logger name] #log-content
-    set_pattern("[%l][%x - %H:%M:%S.%F][" + log_name_ + "] %v");
+    set_pattern("%^[%l][%x - %H:%M:%S.%F][" + log_name_ + "] %v%$");
 }
 
 inline Logger::Logger(std::string&& name) :
@@ -164,13 +164,13 @@ inline Logger::Logger(std::string&& name) :
     //set_pattern("[%t][%H:%M:%S.%F][%l] %v");
     // [log type][MM/DD/YY - hour:minutes:seconds.nanoseconds] #log-content
 //    set_pattern("[%l][%x - %H:%M:%S.%F] %v");
-      set_pattern("[%l][%H:%M:%S] %v");
+      set_pattern("%^[%l][%H:%M:%S] %v%$");
   else
     // Logging pattern is :
     // [logger name][thread num][hour:minutes:seconds.nanoseconds][log type] #log-content
     //set_pattern("[" + log_name_ + "]" +"[%t][%H:%M:%S.%F][%l] %v");
     // [log type][MM/DD/YY - hour:minutes:seconds.nanoseconds][logger name] #log-content
-    set_pattern("[%l][%x - %H:%M:%S.%F][" + log_name_ + "] %v");
+    set_pattern("%^[%l][%x - %H:%M:%S.%F][" + log_name_ + "] %v%$");
 }
 
 inline Logger::~Logger()
diff --git a/test/gtest_logging.cpp b/test/gtest_logging.cpp
index 32da5344d..63927355f 100644
--- a/test/gtest_logging.cpp
+++ b/test/gtest_logging.cpp
@@ -33,26 +33,36 @@
 TEST(logging, info)
 {
     WOLF_INFO("test info ", 5, " ", 0.123);
+    WOLF_INFO_COND(true, "This message should appear!");
+    WOLF_INFO_COND(false, "This message should NOT appear!");
 }
 
 TEST(logging, warn)
 {
     WOLF_WARN("test warn ", 5, " ", 0.123);
+    WOLF_WARN_COND(true, "This message should appear!");
+    WOLF_WARN_COND(false, "This message should NOT appear!");
 }
 
 TEST(logging, error)
 {
     WOLF_ERROR("test error ", 5, " ", 0.123);
+    WOLF_ERROR_COND(true, "This message should appear!");
+    WOLF_ERROR_COND(false, "This message should NOT appear!");
 }
 
 TEST(logging, trace)
 {
     WOLF_TRACE("test trace ", 5, " ", 0.123);
+    WOLF_TRACE_COND(true, "This message should appear!");
+    WOLF_TRACE_COND(false, "This message should NOT appear!");
 }
 
 TEST(logging, debug)
 {
     WOLF_DEBUG("test debug ", 5, " ", 0.123);
+    WOLF_DEBUG_COND(true, "This message should appear!");
+    WOLF_DEBUG_COND(false, "This message should NOT appear!");
 }
 
 int main(int argc, char **argv)
-- 
GitLab