basic_file_sink-inl.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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, bool truncate, const file_event_handlers &event_handlers)
  13. : file_helper_{event_handlers}
  14. {
  15. file_helper_.open(filename, truncate);
  16. }
  17. template<typename Mutex>
  18. SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const
  19. {
  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. {
  25. memory_buf_t formatted;
  26. base_sink<Mutex>::formatter_->format(msg, formatted);
  27. file_helper_.write(formatted);
  28. }
  29. template<typename Mutex>
  30. SPDLOG_INLINE void basic_file_sink<Mutex>::flush_()
  31. {
  32. file_helper_.flush();
  33. }
  34. } // namespace sinks
  35. } // namespace spdlog