Agora  1.2.0
Agora project
msvc_sink.h
Go to the documentation of this file.
1 // Copyright(c) 2016 Alexander Dalshov.
2 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
3 
4 #pragma once
5 
6 #if defined(_WIN32)
7 
9 # include <spdlog/sinks/base_sink.h>
10 
11 # include <mutex>
12 # include <string>
13 
14 // Avoid including windows.h (https://stackoverflow.com/a/30741042)
15 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
16 
17 namespace spdlog {
18 namespace sinks {
19 /*
20  * MSVC sink (logging using OutputDebugStringA)
21  */
22 template<typename Mutex>
23 class msvc_sink : public base_sink<Mutex>
24 {
25 public:
26  msvc_sink() = default;
27 
28 protected:
29  void sink_it_(const details::log_msg &msg) override
30  {
31  memory_buf_t formatted;
32  base_sink<Mutex>::formatter_->format(msg, formatted);
33 # ifdef SPDLOG_USE_STD_FORMAT
34  OutputDebugStringA(formatted.c_str());
35 # else
36  OutputDebugStringA(fmt::to_string(formatted).c_str());
37 # endif
38  }
39 
40  void flush_() override {}
41 };
42 
43 using msvc_sink_mt = msvc_sink<std::mutex>;
44 using msvc_sink_st = msvc_sink<details::null_mutex>;
45 
46 using windebug_sink_mt = msvc_sink_mt;
47 using windebug_sink_st = msvc_sink_st;
48 
49 } // namespace sinks
50 } // namespace spdlog
51 
52 #endif
base_sink.h
spdlog::sinks::base_sink::formatter_
std::unique_ptr< spdlog::formatter > formatter_
Definition: base_sink.h:39
null_mutex.h
spdlog
Definition: async.h:25
fmt::v8::to_string
auto to_string(const T &value) -> std::string
Definition: format.h:2882
spdlog::memory_buf_t
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition: common.h:155