]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Formatter: write the pending string on flush
authorPatrick Donnelly <pdonnell@redhat.com>
Thu, 9 May 2024 14:08:22 +0000 (10:08 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Mon, 3 Mar 2025 20:00:53 +0000 (15:00 -0500)
The formatter would be deleted and automatically flush anyway but this is
conforming to the API.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
(cherry picked from commit 5a3584b07821f5cc481817dbd0c8323df1c9f163)

src/common/Formatter.h

index 65ffb0a68551edeed5a783e0fdf524d172e7e805..4bfb5c41e08d50d6d731e01d0b060c6dd0e090d6 100644 (file)
@@ -200,7 +200,7 @@ namespace ceph {
     int get_len() const override;
     void write_raw_data(const char *data) override;
 
-  protected:
+protected:
     virtual bool handle_value(std::string_view name, std::string_view s, bool quoted) {
       return false; /* is handling done? */
     }
@@ -219,8 +219,9 @@ namespace ceph {
       return m_ss;
     }
 
-  private:
+    void finish_pending_string();
 
+private:
     struct json_formatter_stack_entry_d {
       int size = 0;
       bool is_array = false;
@@ -231,7 +232,6 @@ namespace ceph {
     void print_quoted_string(std::string_view s);
     void print_name(std::string_view name);
     void print_comma(json_formatter_stack_entry_d& entry);
-    void finish_pending_string();
 
     template <class T>
     void add_value(std::string_view name, T val);
@@ -254,6 +254,14 @@ public:
     {
     }
     ~JSONFormatterFile() {
+      flush();
+    }
+
+    void flush(std::ostream& os) override {
+      flush();
+    }
+    void flush() {
+      JSONFormatter::finish_pending_string();
       file.flush();
     }