diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index 4893c05c..1170112a 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -5,10 +5,9 @@ #pragma once -#include #include -#include +#include #include #include @@ -18,16 +17,27 @@ namespace sinks { template -class stdout_sink : public ostream_sink +class stdout_sink : public base_sink { using MyType = stdout_sink; public: - stdout_sink() : ostream_sink(std::cout, true) {} + stdout_sink() {} static std::shared_ptr instance() { static std::shared_ptr instance = std::make_shared(); return instance; } + + void _sink_it(const details::log_msg& msg) override + { + fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), stdout); + flush(); + } + + void flush() override + { + fflush(stdout); + } }; typedef stdout_sink stdout_sink_st; @@ -35,17 +45,27 @@ typedef stdout_sink stdout_sink_mt; template -class stderr_sink : public ostream_sink +class stderr_sink : public base_sink { using MyType = stderr_sink; public: - stderr_sink() : ostream_sink(std::cerr, true) {} + stderr_sink() {} static std::shared_ptr instance() { static std::shared_ptr instance = std::make_shared(); return instance; } + + void _sink_it(const details::log_msg& msg) override + { + fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), stderr); + flush(); + } + void flush() override + { + fflush(stderr); + } }; typedef stderr_sink stderr_sink_mt;