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