From ba68a2d05dd7eb9968d6a53ffcb5cf5b4318ac69 Mon Sep 17 00:00:00 2001 From: Anton Goryunov Date: Thu, 14 Apr 2016 23:05:05 +0300 Subject: [PATCH] - std::cout replaced with fwrite to stdout in console sink --- include/spdlog/sinks/stdout_sinks.h | 32 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) 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;