mirror of
https://github.com/gabime/spdlog.git
synced 2025-03-31 10:22:41 +08:00

Some checks failed
macos / macOS Clang (C++17, Release) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:OFF BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Failing after 4s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Failing after 2s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Failing after 2s
51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
// Copyright(c) 2016 Alexander Dalshov & spdlog contributors.
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
#pragma once
|
|
|
|
#include <mutex>
|
|
|
|
#include "../details/null_mutex.h"
|
|
#include "./base_sink.h"
|
|
|
|
// Avoid including windows.h (https://stackoverflow.com/a/30741042)
|
|
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
|
|
extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
|
|
|
|
namespace spdlog {
|
|
namespace sinks {
|
|
/*
|
|
* MSVC sink (logging using OutputDebugStringA)
|
|
*/
|
|
template <typename Mutex>
|
|
class msvc_sink final : public base_sink<Mutex> {
|
|
public:
|
|
msvc_sink() = default;
|
|
explicit msvc_sink(bool check_debugger_present)
|
|
: check_debugger_present_{check_debugger_present} {}
|
|
|
|
protected:
|
|
void sink_it_(const details::log_msg &msg) override {
|
|
if (check_debugger_present_ && !IsDebuggerPresent()) {
|
|
return;
|
|
}
|
|
memory_buf_t formatted;
|
|
base_sink<Mutex>::formatter_->format(msg, formatted);
|
|
formatted.push_back('\0'); // add a null terminator for OutputDebugString
|
|
OutputDebugStringA(formatted.data());
|
|
}
|
|
|
|
void flush_() override {}
|
|
|
|
bool check_debugger_present_ = true;
|
|
};
|
|
|
|
using msvc_sink_mt = msvc_sink<std::mutex>;
|
|
using msvc_sink_st = msvc_sink<details::null_mutex>;
|
|
|
|
using windebug_sink_mt = msvc_sink_mt;
|
|
using windebug_sink_st = msvc_sink_st;
|
|
|
|
} // namespace sinks
|
|
} // namespace spdlog
|