basic_file_sink-inl.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
  2. // Distributed under the MIT License (http://opensource.org/licenses/MIT)
  3. #pragma once
  4. #ifndef SPDLOG_HEADER_ONLY
  5. #include <spdlog/sinks/basic_file_sink.h>
  6. #endif
  7. #include <spdlog/common.h>
  8. #include <spdlog/details/os.h>
  9. namespace spdlog {
  10. namespace sinks {
  11. template <typename Mutex>
  12. SPDLOG_INLINE basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename,
  13. bool truncate,
  14. const file_event_handlers &event_handlers)
  15. : file_helper_{event_handlers} {
  16. file_helper_.open(filename, truncate);
  17. }
  18. template <typename Mutex>
  19. SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const {
  20. return file_helper_.filename();
  21. }
  22. template <typename Mutex>
  23. SPDLOG_INLINE void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg) {
  24. memory_buf_t formatted;
  25. base_sink<Mutex>::formatter_->format(msg, formatted);
  26. file_helper_.write(formatted);
  27. }
  28. template <typename Mutex>
  29. SPDLOG_INLINE void basic_file_sink<Mutex>::flush_() {
  30. file_helper_.flush();
  31. }
  32. } // namespace sinks
  33. } // namespace spdlog