This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git


The following commit(s) were added to refs/heads/main by this push:
     new 45d30014 style(cpp): rename logging level with "FURY_" prefix (#2016)
45d30014 is described below

commit 45d30014751c2aaefbe26387ed099b7a6f0683d9
Author: Junduo Dong <[email protected]>
AuthorDate: Tue Jan 21 12:24:25 2025 +0800

    style(cpp): rename logging level with "FURY_" prefix (#2016)
    
    ## What does this PR do?
    
    Thus the duplicated macro problem could be solved.
    
    ## Related issues
    
    ## Does this PR introduce any user-facing change?
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    ## Benchmark
    
    ---------
    
    Signed-off-by: Junduo Dong <[email protected]>
---
 cpp/fury/util/logging.cc          | 26 ++++++++++++++------------
 cpp/fury/util/logging.h           | 12 ++++++------
 cpp/fury/util/logging_test.cc     |  6 +++---
 cpp/fury/util/string_util_test.cc | 35 +++++++++++++++++++----------------
 4 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/cpp/fury/util/logging.cc b/cpp/fury/util/logging.cc
index 9718a31b..81925099 100644
--- a/cpp/fury/util/logging.cc
+++ b/cpp/fury/util/logging.cc
@@ -51,9 +51,11 @@ std::string GetCallTrace() {
 }
 
 std::unordered_map<FuryLogLevel, std::string> log_level_to_str = {
-    {FuryLogLevel::DEBUG, "DEBUG"},     {FuryLogLevel::INFO, "INFO"},
-    {FuryLogLevel::WARNING, "WARNING"}, {FuryLogLevel::ERR, "ERROR"},
-    {FuryLogLevel::FATAL, "FATAL"},
+    {FuryLogLevel::FURY_DEBUG, "DEBUG"},
+    {FuryLogLevel::FURY_INFO, "INFO"},
+    {FuryLogLevel::FURY_WARNING, "WARNING"},
+    {FuryLogLevel::FURY_ERROR, "ERROR"},
+    {FuryLogLevel::FURY_FATAL, "FATAL"},
 };
 
 std::string LogLevelAsString(FuryLogLevel level) {
@@ -65,26 +67,26 @@ std::string LogLevelAsString(FuryLogLevel level) {
 }
 
 FuryLogLevel FuryLog::GetLogLevel() {
-  FuryLogLevel severity_threshold = FuryLogLevel::INFO;
+  FuryLogLevel severity_threshold = FuryLogLevel::FURY_INFO;
   const char *var_value = std::getenv("FURY_LOG_LEVEL");
   if (var_value != nullptr) {
     std::string data = var_value;
     std::transform(data.begin(), data.end(), data.begin(), ::tolower);
     if (data == "debug") {
-      severity_threshold = FuryLogLevel::DEBUG;
+      severity_threshold = FuryLogLevel::FURY_DEBUG;
     } else if (data == "info") {
-      severity_threshold = FuryLogLevel::INFO;
+      severity_threshold = FuryLogLevel::FURY_INFO;
     } else if (data == "warning") {
-      severity_threshold = FuryLogLevel::WARNING;
+      severity_threshold = FuryLogLevel::FURY_WARNING;
     } else if (data == "error") {
-      severity_threshold = FuryLogLevel::ERR;
+      severity_threshold = FuryLogLevel::FURY_ERROR;
     } else if (data == "fatal") {
-      severity_threshold = FuryLogLevel::FATAL;
+      severity_threshold = FuryLogLevel::FURY_FATAL;
     } else {
-      FURY_LOG_INTERNAL(WARNING)
+      FURY_LOG_INTERNAL(FURY_WARNING)
           << "Unrecognized setting of FuryLogLevel=" << var_value;
     }
-    FURY_LOG_INTERNAL(INFO)
+    FURY_LOG_INTERNAL(FURY_INFO)
         << "Set ray log level from environment variable RAY_BACKEND_LOG_LEVEL"
         << " to " << static_cast<int>(severity_threshold);
   }
@@ -99,7 +101,7 @@ FuryLog::FuryLog(const char *file_name, int line_number, 
FuryLogLevel severity)
 }
 
 FuryLog::~FuryLog() {
-  if (severity_ == FuryLogLevel::FATAL) {
+  if (severity_ == FuryLogLevel::FURY_FATAL) {
     Stream() << "\n*** StackTrace Information ***\n" << ::fury::GetCallTrace();
     Stream() << std::endl;
     std::_Exit(EXIT_FAILURE);
diff --git a/cpp/fury/util/logging.h b/cpp/fury/util/logging.h
index addb2102..682a03df 100644
--- a/cpp/fury/util/logging.h
+++ b/cpp/fury/util/logging.h
@@ -32,11 +32,11 @@ std::string GetCallTrace();
 // Simple logging implementation to avoid introduce glog dependency.
 
 enum class FuryLogLevel {
-  DEBUG = -1,
-  INFO = 0,
-  WARNING = 1,
-  ERR = 2,
-  FATAL = 3
+  FURY_DEBUG = -1,
+  FURY_INFO = 0,
+  FURY_WARNING = 1,
+  FURY_ERROR = 2,
+  FURY_FATAL = 3
 };
 
 #define FURY_LOG_INTERNAL(level)                                               
\
@@ -51,7 +51,7 @@ enum class FuryLogLevel {
 
 #define FURY_CHECK(condition)                                                  
\
   if (!(condition))                                                            
\
-  FURY_LOG_INTERNAL(FATAL) << " Check failed: " #condition " "
+  FURY_LOG_INTERNAL(FURY_FATAL) << " Check failed: " #condition " "
 
 #define FURY_CHECK_OP(left, op, right)                                         
\
   do {                                                                         
\
diff --git a/cpp/fury/util/logging_test.cc b/cpp/fury/util/logging_test.cc
index 7a8a84a4..947dac60 100644
--- a/cpp/fury/util/logging_test.cc
+++ b/cpp/fury/util/logging_test.cc
@@ -28,8 +28,8 @@
 namespace fury {
 
 TEST(PrintLogTest, BasicLog) {
-  FURY_LOG(INFO) << "test info";
-  ASSERT_DEATH(FURY_LOG(FATAL) << "test fatal",
+  FURY_LOG(FURY_INFO) << "test info";
+  ASSERT_DEATH(FURY_LOG(FURY_FATAL) << "test fatal",
                "\\[.*\\] FATAL cpp/fury/util/logging_test.cc:.*: test fatal");
 }
 
@@ -70,7 +70,7 @@ std::string TestFunctionLevel2() { return 
TestFunctionLevel1(); }
 #ifndef _WIN32
 TEST(PrintLogTest, CallstackTraceTest) {
   auto ret = TestFunctionLevel2();
-  FURY_LOG(INFO) << "stack trace:\n" << ret;
+  FURY_LOG(FURY_INFO) << "stack trace:\n" << ret;
   // work for linux
   // EXPECT_TRUE(ret.find("TestFunctionLevel0") != std::string::npos);
   // work for mac
diff --git a/cpp/fury/util/string_util_test.cc 
b/cpp/fury/util/string_util_test.cc
index f57f7518..220fa544 100644
--- a/cpp/fury/util/string_util_test.cc
+++ b/cpp/fury/util/string_util_test.cc
@@ -63,7 +63,7 @@ TEST(StringUtilTest, TestisAsciiFunctions) {
   auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
                       end_time - start_time)
                       .count();
-  FURY_LOG(INFO) << "BaseLine Running Time: " << duration << " ns.";
+  FURY_LOG(FURY_INFO) << "BaseLine Running Time: " << duration << " ns.";
 
   start_time = std::chrono::high_resolution_clock::now();
   result = isAscii(testStr);
@@ -71,7 +71,7 @@ TEST(StringUtilTest, TestisAsciiFunctions) {
   duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time -
                                                                   start_time)
                  .count();
-  FURY_LOG(INFO) << "Optimized Running Time: " << duration << " ns.";
+  FURY_LOG(FURY_INFO) << "Optimized Running Time: " << duration << " ns.";
 
   EXPECT_TRUE(result);
 }
@@ -286,9 +286,10 @@ TEST(UTF16ToUTF8Test, PerformanceTest) {
     auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
                         end_time - start_time)
                         .count();
-    FURY_LOG(INFO) << "Standard library Running Time: " << duration << " ns";
+    FURY_LOG(FURY_INFO) << "Standard library Running Time: " << duration
+                        << " ns";
   } catch (const std::exception &e) {
-    FURY_LOG(FATAL) << "Caught exception: " << e.what();
+    FURY_LOG(FURY_FATAL) << "Caught exception: " << e.what();
   }
 
   // BaseLine
@@ -301,9 +302,9 @@ TEST(UTF16ToUTF8Test, PerformanceTest) {
     auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
                         end_time - start_time)
                         .count();
-    FURY_LOG(INFO) << "Baseline Running Time: " << duration << " ns";
+    FURY_LOG(FURY_INFO) << "Baseline Running Time: " << duration << " ns";
   } catch (const std::exception &e) {
-    FURY_LOG(FATAL) << "Caught exception: " << e.what();
+    FURY_LOG(FURY_FATAL) << "Caught exception: " << e.what();
   }
 
   // SIMD
@@ -316,9 +317,9 @@ TEST(UTF16ToUTF8Test, PerformanceTest) {
     auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
                         end_time - start_time)
                         .count();
-    FURY_LOG(INFO) << "SIMD Running Time: " << duration << " ns";
+    FURY_LOG(FURY_INFO) << "SIMD Running Time: " << duration << " ns";
   } catch (const std::exception &e) {
-    FURY_LOG(FATAL) << "Caught exception: " << e.what();
+    FURY_LOG(FURY_FATAL) << "Caught exception: " << e.what();
   }
 }
 
@@ -523,10 +524,11 @@ TEST(UTF8ToUTF16Test, PerformanceTest) {
     auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
                         end_time - start_time)
                         .count();
-    FURY_LOG(INFO) << "Standard Library Running Time: " << duration << " ns";
+    FURY_LOG(FURY_INFO) << "Standard Library Running Time: " << duration
+                        << " ns";
   } catch (const std::exception &e) {
-    FURY_LOG(FATAL) << "Caught exception in standard library conversion: "
-                    << e.what();
+    FURY_LOG(FURY_FATAL) << "Caught exception in standard library conversion: "
+                         << e.what();
   }
 
   // BaseLine
@@ -539,9 +541,10 @@ TEST(UTF8ToUTF16Test, PerformanceTest) {
     auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
                         end_time - start_time)
                         .count();
-    FURY_LOG(INFO) << "BaseLine Running Time: " << duration << " ns";
+    FURY_LOG(FURY_INFO) << "BaseLine Running Time: " << duration << " ns";
   } catch (const std::exception &e) {
-    FURY_LOG(FATAL) << "Caught exception in baseline conversion: " << e.what();
+    FURY_LOG(FURY_FATAL) << "Caught exception in baseline conversion: "
+                         << e.what();
   }
 
   // Optimized (SIMD)
@@ -554,10 +557,10 @@ TEST(UTF8ToUTF16Test, PerformanceTest) {
     auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
                         end_time - start_time)
                         .count();
-    FURY_LOG(INFO) << "SIMD Optimized Running Time: " << duration << " ns";
+    FURY_LOG(FURY_INFO) << "SIMD Optimized Running Time: " << duration << " 
ns";
   } catch (const std::exception &e) {
-    FURY_LOG(FATAL) << "Caught exception in SIMD optimized conversion: "
-                    << e.what();
+    FURY_LOG(FURY_FATAL) << "Caught exception in SIMD optimized conversion: "
+                         << e.what();
   }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to