base_sink.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
  2. // Distributed under the MIT License (http://opensource.org/licenses/MIT)
  3. #pragma once
  4. //
  5. // base sink templated over a mutex (either dummy or real)
  6. // concrete implementation should override the sink_it_() and flush_() methods.
  7. // locking is taken care of in this class - no locking needed by the
  8. // implementers..
  9. //
  10. #include <spdlog/common.h>
  11. #include <spdlog/details/log_msg.h>
  12. #include <spdlog/sinks/sink.h>
  13. namespace spdlog {
  14. namespace sinks {
  15. template <typename Mutex>
  16. class SPDLOG_API base_sink : public sink {
  17. public:
  18. base_sink();
  19. explicit base_sink(std::unique_ptr<spdlog::formatter> formatter);
  20. ~base_sink() override = default;
  21. base_sink(const base_sink &) = delete;
  22. base_sink(base_sink &&) = delete;
  23. base_sink &operator=(const base_sink &) = delete;
  24. base_sink &operator=(base_sink &&) = delete;
  25. void log(const details::log_msg &msg) final;
  26. void flush() final;
  27. void set_pattern(const std::string &pattern) final;
  28. void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final;
  29. protected:
  30. // sink formatter
  31. std::unique_ptr<spdlog::formatter> formatter_;
  32. Mutex mutex_;
  33. virtual void sink_it_(const details::log_msg &msg) = 0;
  34. virtual void flush_() = 0;
  35. virtual void set_pattern_(const std::string &pattern);
  36. virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter);
  37. };
  38. } // namespace sinks
  39. } // namespace spdlog
  40. #ifdef SPDLOG_HEADER_ONLY
  41. #include "base_sink-inl.h"
  42. #endif