Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:58:15

0001 // Copyright(c) 2016 Alexander Dalshov & spdlog contributors.
0002 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
0003 
0004 #pragma once
0005 
0006 
0007 #if defined(_WIN32)
0008 
0009 #    include <spdlog/details/null_mutex.h>
0010 #    include <spdlog/sinks/base_sink.h>
0011 
0012 #    include <mutex>
0013 #    include <string>
0014 
0015 // Avoid including windows.h (https://stackoverflow.com/a/30741042)
0016 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
0017 extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
0018 
0019 namespace spdlog {
0020 namespace sinks {
0021 /*
0022  * MSVC sink (logging using OutputDebugStringA)
0023  */
0024 template<typename Mutex>
0025 class msvc_sink : public base_sink<Mutex>
0026 {
0027 public:
0028     msvc_sink() = default;
0029     msvc_sink(bool check_ebugger_present)
0030         : check_debbugger_present_{check_ebugger_present} {};
0031 
0032 protected:
0033     void sink_it_(const details::log_msg &msg) override
0034     {
0035         if (check_debbugger_present_ && !IsDebuggerPresent())
0036         {
0037             return;
0038         }
0039         memory_buf_t formatted;
0040         base_sink<Mutex>::formatter_->format(msg, formatted);
0041         formatted.push_back('\0'); // add a null terminator for OutputDebugStringA
0042         OutputDebugStringA(formatted.data());
0043     }
0044 
0045     void flush_() override {}
0046 
0047     bool check_debbugger_present_ = true;
0048 };
0049 
0050 using msvc_sink_mt = msvc_sink<std::mutex>;
0051 using msvc_sink_st = msvc_sink<details::null_mutex>;
0052 
0053 using windebug_sink_mt = msvc_sink_mt;
0054 using windebug_sink_st = msvc_sink_st;
0055 
0056 } // namespace sinks
0057 } // namespace spdlog
0058 
0059 #endif