spdlog
Loading...
Searching...
No Matches
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
10
11# include <mutex>
12# include <string>
13
14// Avoid including windows.h (https://stackoverflow.com/a/30741042)
15extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
16
17namespace spdlog {
18namespace sinks {
19/*
20 * MSVC sink (logging using OutputDebugStringA)
21 */
22template<typename Mutex>
23class msvc_sink : public base_sink<Mutex>
24{
25public:
26 msvc_sink() = default;
27
28protected:
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 OutputDebugStringA(fmt::to_string(formatted).c_str());
34 }
35
36 void flush_() override {}
37};
38
39using msvc_sink_mt = msvc_sink<std::mutex>;
40using msvc_sink_st = msvc_sink<details::null_mutex>;
41
42using windebug_sink_mt = msvc_sink_mt;
43using windebug_sink_st = msvc_sink_st;
44
45} // namespace sinks
46} // namespace spdlog
47
48#endif
Definition async.h:25
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:116