torwig commented on code in PR #2823:
URL: https://github.com/apache/kvrocks/pull/2823#discussion_r2003002906


##########
src/stats/log_collector.cc:
##########
@@ -89,6 +101,37 @@ void LogCollector<T>::PushEntry(std::unique_ptr<T> &&entry) 
{
   entries_.push_front(std::move(entry));
 }
 
+template <>
+void LogCollector<SlowEntry>::PushEntry(std::unique_ptr<SlowEntry> &&entry) {
+  std::lock_guard<std::mutex> guard(mu_);
+  entry->id = ++id_;
+  entry->time = util::GetTimeStamp();
+  if (max_entries_ > 0 && !entries_.empty() && entries_.size() >= 
static_cast<size_t>(max_entries_)) {
+    entries_.pop_back();
+  }
+
+  if (slowlog_save_to_logfile_) {
+    std::string cmd;
+    if (entry->args.size() > 0) {
+      for (const auto &arg: entry->args) {
+        cmd.append(arg).append(" ");
+      }
+      cmd.pop_back();
+    }
+    // json format
+    auto log = fmt::format("[slowlog] {{\"id\":{}, \"timestamp\":{}, 
\"duration\":{}, \"cmd\":\"{}\", "
+        "\"ip\":\"{}\", \"port\":{}, \"client_name\":\"{}\"}}",
+        entry->id, entry->time, entry->duration, cmd, entry->ip, entry->port, 
entry->client_name);

Review Comment:
   @greatsharp I think it's already distinguished since the lines have the 
`[slowlog]` prefix. What @PragmaTwice might suggested was to introduce one more 
option to specify the slow log format (for example, "text" (default) or 
"json"). WDYT, @PragmaTwice ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to