Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 10:29:02

0001 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
0002 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
0003 
0004 #pragma once
0005 
0006 #include <spdlog/details/null_mutex.h>
0007 #include <spdlog/sinks/base_sink.h>
0008 
0009 #include <mutex>
0010 #include <ostream>
0011 
0012 namespace spdlog {
0013 namespace sinks {
0014 template <typename Mutex>
0015 class ostream_sink final : public base_sink<Mutex> {
0016 public:
0017     explicit ostream_sink(std::ostream &os, bool force_flush = false)
0018         : ostream_(os),
0019           force_flush_(force_flush) {}
0020     ostream_sink(const ostream_sink &) = delete;
0021     ostream_sink &operator=(const ostream_sink &) = delete;
0022 
0023 protected:
0024     void sink_it_(const details::log_msg &msg) override {
0025         memory_buf_t formatted;
0026         base_sink<Mutex>::formatter_->format(msg, formatted);
0027         ostream_.write(formatted.data(), static_cast<std::streamsize>(formatted.size()));
0028         if (force_flush_) {
0029             ostream_.flush();
0030         }
0031     }
0032 
0033     void flush_() override { ostream_.flush(); }
0034 
0035     std::ostream &ostream_;
0036     bool force_flush_;
0037 };
0038 
0039 using ostream_sink_mt = ostream_sink<std::mutex>;
0040 using ostream_sink_st = ostream_sink<details::null_mutex>;
0041 
0042 }  // namespace sinks
0043 }  // namespace spdlog