2016-04-20 04:57:49 -04:00
|
|
|
// Copyright(c) 2016 Alexander Dalshov.
|
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-11-14 08:21:14 -05:00
|
|
|
#if defined(_WIN32)
|
2016-04-20 04:57:49 -04:00
|
|
|
|
2018-04-28 18:31:09 -04:00
|
|
|
#include "spdlog/details/null_mutex.h"
|
|
|
|
#include "spdlog/sinks/base_sink.h"
|
2016-04-20 04:57:49 -04:00
|
|
|
|
2017-11-14 08:21:14 -05:00
|
|
|
#include <winbase.h>
|
2016-04-20 04:57:49 -04:00
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
|
2018-03-17 06:47:46 -04:00
|
|
|
namespace spdlog {
|
|
|
|
namespace sinks {
|
2016-04-20 04:57:49 -04:00
|
|
|
/*
|
2018-03-09 08:26:33 -05:00
|
|
|
* MSVC sink (logging using OutputDebugStringA)
|
|
|
|
*/
|
2018-07-14 09:21:53 -04:00
|
|
|
template<typename Mutex>
|
2018-03-16 11:35:56 -04:00
|
|
|
class msvc_sink : public base_sink<Mutex>
|
2016-04-20 04:57:49 -04:00
|
|
|
{
|
|
|
|
public:
|
2018-03-09 08:26:33 -05:00
|
|
|
explicit msvc_sink() {}
|
2016-04-20 04:57:49 -04:00
|
|
|
|
|
|
|
protected:
|
2018-07-17 13:09:05 -04:00
|
|
|
void sink_it_(const details::log_msg &msg) override
|
2016-04-20 04:57:49 -04:00
|
|
|
{
|
2018-07-21 16:48:07 -04:00
|
|
|
|
2018-07-17 13:09:05 -04:00
|
|
|
fmt::memory_buffer formatted;
|
|
|
|
sink::formatter_->format(msg, formatted);
|
2018-07-07 07:04:31 -04:00
|
|
|
OutputDebugStringA(fmt::to_string(formatted).c_str());
|
2016-04-20 04:57:49 -04:00
|
|
|
}
|
2017-05-20 20:43:41 -04:00
|
|
|
|
2018-06-10 15:59:17 -04:00
|
|
|
void flush_() override {}
|
2016-04-20 04:57:49 -04:00
|
|
|
};
|
|
|
|
|
2018-02-24 16:35:09 -05:00
|
|
|
using msvc_sink_mt = msvc_sink<std::mutex>;
|
|
|
|
using msvc_sink_st = msvc_sink<details::null_mutex>;
|
2016-04-20 04:57:49 -04:00
|
|
|
|
2018-07-07 07:04:31 -04:00
|
|
|
using windebug_sink_mt = msvc_sink_mt;
|
|
|
|
using windebug_sink_st = msvc_sink_st;
|
|
|
|
|
2018-03-17 06:47:46 -04:00
|
|
|
} // namespace sinks
|
|
|
|
} // namespace spdlog
|
2016-04-20 04:57:49 -04:00
|
|
|
|
|
|
|
#endif
|