| 10 | namespace ceph { |
| 11 | |
| 12 | class JSONFormatterFile : public JSONFormatter { |
| 13 | public: |
| 14 | JSONFormatterFile(const std::string& path, bool pretty=false) : |
| 15 | JSONFormatter(pretty), |
| 16 | path(path), |
| 17 | file(path, std::ios::out | std::ios::trunc) |
| 18 | { |
| 19 | } |
| 20 | ~JSONFormatterFile() { |
| 21 | flush(); |
| 22 | } |
| 23 | |
| 24 | void flush(std::ostream& os) override { |
| 25 | flush(); |
| 26 | } |
| 27 | void flush() { |
| 28 | JSONFormatter::finish_pending_string(); |
| 29 | file.flush(); |
| 30 | } |
| 31 | |
| 32 | void reset() override { |
| 33 | JSONFormatter::reset(); |
| 34 | file = std::ofstream(path, std::ios::out | std::ios::trunc); |
| 35 | } |
| 36 | int get_len() const override { |
| 37 | return file.tellp(); |
| 38 | } |
| 39 | std::ofstream const& get_ofstream() const { |
| 40 | return file; |
| 41 | } |
| 42 | |
| 43 | protected: |
| 44 | std::ostream& get_ss() override { |
| 45 | return file; |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | std::string path; |
| 50 | mutable std::ofstream file; // mutable for get_len |
| 51 | }; |
| 52 | |
| 53 | } |
| 54 |
no outgoing calls
no test coverage detected