You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
982B

  1. // Copyright(c) 2016 Alexander Dalshov.
  2. // Distributed under the MIT License (http://opensource.org/licenses/MIT)
  3. #pragma once
  4. #if defined(_WIN32)
  5. #include "spdlog/details/null_mutex.h"
  6. #include "spdlog/sinks/base_sink.h"
  7. #include <winbase.h>
  8. #include <mutex>
  9. #include <string>
  10. namespace spdlog {
  11. namespace sinks {
  12. /*
  13. * MSVC sink (logging using OutputDebugStringA)
  14. */
  15. template<typename Mutex>
  16. class msvc_sink : public base_sink<Mutex>
  17. {
  18. public:
  19. explicit msvc_sink() {}
  20. protected:
  21. void sink_it_(const details::log_msg &msg) override
  22. {
  23. memory_buf_t formatted;
  24. base_sink<Mutex>::formatter_->format(msg, formatted);
  25. OutputDebugStringA(fmt::to_string(formatted).c_str());
  26. }
  27. void flush_() override {}
  28. };
  29. using msvc_sink_mt = msvc_sink<std::mutex>;
  30. using msvc_sink_st = msvc_sink<details::null_mutex>;
  31. using windebug_sink_mt = msvc_sink_mt;
  32. using windebug_sink_st = msvc_sink_st;
  33. } // namespace sinks
  34. } // namespace spdlog
  35. #endif