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

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new a352409db chore(log): replace logging calls in storage/rdb (#2936)
a352409db is described below

commit a352409dba15e84d5a91daf51350296de003eec1
Author: Twice <[email protected]>
AuthorDate: Wed May 7 16:11:40 2025 +0800

    chore(log): replace logging calls in storage/rdb (#2936)
    
    Signed-off-by: PragmaTwice <[email protected]>
---
 src/common/logging.h         | 43 -------------------------------------------
 src/config/config.cc         |  2 +-
 src/storage/batch_debugger.h |  2 +-
 src/storage/rdb/rdb.cc       | 40 ++++++++++++++++++++--------------------
 4 files changed, 22 insertions(+), 65 deletions(-)

diff --git a/src/common/logging.h b/src/common/logging.h
index c2ddc2f56..e145fa5a0 100644
--- a/src/common/logging.h
+++ b/src/common/logging.h
@@ -75,49 +75,6 @@ template <typename... Args>
   fatal({"UNREACHABLE REACHED: please submit a bug report with the stacktrace 
below.", loc});
 }
 
-// This is a simulation of glog API, with a spdlog backend.
-// TODO: We use it as a transition from glog to spdlog,
-// and it will be removed when the migration is complete.
-template <spdlog::level::level_enum level>
-struct GlogInterface {  // NOLINT
-  explicit GlogInterface(spdlog::source_loc loc = CurrentLocation()) : 
loc(loc) {}
-
-  template <typename T>
-  friend GlogInterface &&operator<<(GlogInterface &&self, const T &v) {
-    fmt::format_to(std::back_inserter(self.os), "{}", fmt::streamed(v));
-    return std::move(self);
-  }
-
-  ~GlogInterface() {
-    spdlog::default_logger_raw()->log(loc, level, "{}", os);
-    if constexpr (level == spdlog::level::critical) {
-      std::abort();
-    }
-  }
-
-  std::string os;
-  spdlog::source_loc loc;
-};
-
-using GlogInterface_INFO = GlogInterface<spdlog::level::info>;       // NOLINT
-using GlogInterface_WARNING = GlogInterface<spdlog::level::warn>;    // NOLINT
-using GlogInterface_ERROR = GlogInterface<spdlog::level::err>;       // NOLINT
-using GlogInterface_FATAL = GlogInterface<spdlog::level::critical>;  // NOLINT
-
-inline constexpr bool GLOG_IN_DEBUG =
-#ifdef NDEBUG
-    false;
-#else
-    true;
-#endif
-
-// NOLINTNEXTLINE
-#define LOG(level) GlogInterface_##level()
-
-// NOLINTNEXTLINE
-#define DLOG(level) \
-  if constexpr (GLOG_IN_DEBUG) LOG(level)
-
 // NOLINTNEXTLINE
 #define CHECK(cond) \
   if (!(cond)) fatal("Check `{}` failed.", #cond);
diff --git a/src/config/config.cc b/src/config/config.cc
index d942eef9c..2a6dac050 100644
--- a/src/config/config.cc
+++ b/src/config/config.cc
@@ -489,7 +489,7 @@ void Config::initFieldCallback() {
            backup_dir = v;
          }
          if (!previous_backup.empty() && srv != nullptr && !srv->IsLoading()) {
-           // LOG(INFO) should be called after log is initialized and server 
is loaded.
+           // info() should be called after log is initialized and server is 
loaded.
            info("change backup dir from {} to {}", previous_backup, v);
          }
          return Status::OK();
diff --git a/src/storage/batch_debugger.h b/src/storage/batch_debugger.h
index 39e98e3fb..4160c6159 100644
--- a/src/storage/batch_debugger.h
+++ b/src/storage/batch_debugger.h
@@ -28,7 +28,7 @@
 /// ```
 /// WriteBatchInspector inspector;
 /// status = write_batch.Iterate(&inspector);
-/// LOG(INFO) << inspector.seen << ", cnt: " << inspector.cnt;
+/// info("{}, cnt: {}", inspector.seen, inspector.cnt);
 /// ```
 struct WriteBatchInspector : public rocksdb::WriteBatch::Handler {
   std::string seen;
diff --git a/src/storage/rdb/rdb.cc b/src/storage/rdb/rdb.cc
index 40b1bd3f6..78c52b0b6 100644
--- a/src/storage/rdb/rdb.cc
+++ b/src/storage/rdb/rdb.cc
@@ -75,8 +75,8 @@ constexpr const int MinRdbVersionToVerifyChecksum = 5;
 template <typename T>
 T LogWhenError(T &&s) {
   if (!s) {
-    LOG(WARNING) << "Short read or unsupported type loading DB. Unrecoverable 
error, aborting now.";
-    LOG(ERROR) << "Unexpected EOF reading RDB file";
+    warn("Short read or unsupported type loading DB. Unrecoverable error, 
aborting now.");
+    error("Unexpected EOF reading RDB file");
   }
   return std::forward<T>(s);
 }
@@ -560,13 +560,13 @@ Status RDB::LoadRdb(engine::Context &ctx, uint32_t 
db_index, bool overwrite_exis
   buf[9] = '\0';
 
   if (memcmp(buf, "REDIS", 5) != 0) {
-    LOG(WARNING) << "Wrong signature trying to load DB from file";
+    warn("Wrong signature trying to load DB from file");
     return {Status::NotOK, "Wrong signature trying to load DB from file"};
   }
 
   auto rdb_ver = std::atoi(buf + 5);
   if (rdb_ver < 1 || rdb_ver > SupportedRDBVersion) {
-    LOG(WARNING) << "Can't handle RDB format version " << rdb_ver;
+    warn("Can't handle RDB format version {}", rdb_ver);
     return {Status::NotOK, fmt::format("Can't handle RDB format version {}", 
rdb_ver)};
   }
 
@@ -611,14 +611,14 @@ Status RDB::LoadRdb(engine::Context &ctx, uint32_t 
db_index, bool overwrite_exis
       auto value = GET_OR_RET(LogWhenError(LoadStringObject()));
       continue;
     } else if (type == RDBOpcodeModuleAux) {
-      LOG(WARNING) << "RDB module not supported";
+      warn("RDB module not supported");
       return {Status::NotOK, "RDB module not supported"};
     } else if (type == RDBOpcodeFunction || type == RDBOpcodeFunction2) {
-      LOG(WARNING) << "RDB function not supported";
+      warn("RDB function not supported");
       return {Status::NotOK, "RDB function not supported"};
     } else {
       if (!isObjectType(type)) {
-        LOG(WARNING) << "Invalid or Not supported object type: " << type;
+        warn("Invalid or Not supported object type: {}", (int)type);
         return {Status::NotOK, fmt::format("Invalid or Not supported object 
type {}", type)};
       }
     }
@@ -636,7 +636,7 @@ Status RDB::LoadRdb(engine::Context &ctx, uint32_t 
db_index, bool overwrite_exis
        * in an RDB file, instead we will silently discard it and
        * continue loading. */
       if (empty_keys_skipped++ < 10) {  // only log 10 empty keys, just as 
redis does.
-        LOG(WARNING) << "skipping empty key: " << key;
+        warn("skipping empty key: {}", key);
       }
       continue;
     } else if (expire_time_ms != 0 &&
@@ -651,7 +651,7 @@ Status RDB::LoadRdb(engine::Context &ctx, uint32_t 
db_index, bool overwrite_exis
       if (!s.IsNotFound()) {
         skip_exist_keys++;  // skip it even it's not okay
         if (!s.ok()) {
-          LOG(ERROR) << "check key " << key << " exist failed: " << 
s.ToString();
+          error("check key {} exist failed: {}", key, s.ToString());
         }
         continue;
       }
@@ -659,7 +659,7 @@ Status RDB::LoadRdb(engine::Context &ctx, uint32_t 
db_index, bool overwrite_exis
 
     auto ret = saveRdbObject(ctx, type, key, value, expire_time_ms);
     if (!ret.IsOK()) {
-      LOG(WARNING) << "save rdb object key " << key << " failed: " << 
ret.Msg();
+      warn("save rdb object key {} failed: {}", key, ret.Msg());
     } else {
       load_keys++;
     }
@@ -671,17 +671,17 @@ Status RDB::LoadRdb(engine::Context &ctx, uint32_t 
db_index, bool overwrite_exis
     auto expected = GET_OR_RET(LogWhenError(stream_->GetCheckSum()));
     GET_OR_RET(LogWhenError(stream_->Read(reinterpret_cast<char *>(&chk_sum), 
RDBCheckSumLen)));
     if (chk_sum == 0) {
-      LOG(WARNING) << "RDB file was saved with checksum disabled: no check 
performed.";
+      warn("RDB file was saved with checksum disabled: no check performed.");
     } else if (chk_sum != expected) {
-      LOG(WARNING) << "Wrong RDB checksum expected: " << chk_sum << " got: " 
<< expected;
+      warn("Wrong RDB checksum expected: {} got: {}", chk_sum, expected);
       return {Status::NotOK, "All objects were processed and loaded but the 
checksum is unexpected!"};
     }
   }
 
   std::string skip_info = (overwrite_exist_key ? ", exist keys skipped: " + 
std::to_string(skip_exist_keys) : "");
 
-  LOG(INFO) << "Done loading RDB,  keys loaded: " << load_keys << ", keys 
expired:" << expire_keys
-            << ", empty keys skipped: " << empty_keys_skipped << skip_info;
+  info("Done loading RDB, keys loaded: {}, keys expired: {}, empty keys 
skipped: {}{}", load_keys, expire_keys,
+       empty_keys_skipped, skip_info);
 
   return Status::OK();
 }
@@ -731,7 +731,7 @@ Status RDB::SaveObjectType(const RedisType type) {
   } else if (type == kRedisZSet) {
     robj_type = RDBTypeZSet2;
   } else {
-    LOG(WARNING) << "Invalid or Not supported object type: " << type;
+    warn("Invalid or Not supported object type: {}", (int)type);
     return {Status::NotOK, "Invalid or Not supported object type"};
   }
   return stream_->Write((const char *)(&robj_type), 1);
@@ -794,7 +794,7 @@ Status RDB::SaveObject(const std::string &key, const 
RedisType type) {
     }
     return SaveStringObject(value);
   } else {
-    LOG(WARNING) << "Invalid or Not supported object type: " << type;
+    warn("Invalid or Not supported object type: {}", (int)type);
     return {Status::NotOK, "Invalid or Not supported object type"};
   }
 }
@@ -871,7 +871,7 @@ Status RDB::SaveListObject(const std::vector<std::string> 
&elems) {
       if (!status.IsOK()) return status;
     }
   } else {
-    LOG(WARNING) << "the size of elems is zero";
+    warn("the size of elems is zero");
     return {Status::NotOK, "the size of elems is zero"};
   }
   return Status::OK();
@@ -887,7 +887,7 @@ Status RDB::SaveSetObject(const std::vector<std::string> 
&members) {
       if (!status.IsOK()) return status;
     }
   } else {
-    LOG(WARNING) << "the size of elems is zero";
+    warn("the size of elems is zero");
     return {Status::NotOK, "the size of elems is zero"};
   }
   return Status::OK();
@@ -906,7 +906,7 @@ Status RDB::SaveZSetObject(const std::vector<MemberScore> 
&member_scores) {
       if (!status.IsOK()) return status;
     }
   } else {
-    LOG(WARNING) << "the size of member_scores is zero";
+    warn("the size of member_scores is zero");
     return {Status::NotOK, "the size of ZSet is 0"};
   }
   return Status::OK();
@@ -925,7 +925,7 @@ Status RDB::SaveHashObject(const std::vector<FieldValue> 
&field_values) {
       if (!status.IsOK()) return status;
     }
   } else {
-    LOG(WARNING) << "the size of field_values is zero";
+    warn("the size of field_values is zero");
     return {Status::NotOK, "the size of Hash is 0"};
   }
   return Status::OK();

Reply via email to