From ba68a2d05dd7eb9968d6a53ffcb5cf5b4318ac69 Mon Sep 17 00:00:00 2001 From: Anton Goryunov Date: Thu, 14 Apr 2016 23:05:05 +0300 Subject: [PATCH 1/2] - 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; From e0f08d6b29fd2b35599d316f4444aeb607791e5a Mon Sep 17 00:00:00 2001 From: Anton Goryunov Date: Thu, 14 Apr 2016 23:33:51 +0300 Subject: [PATCH 2/2] - fixed includes in tests --- tests/includes.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/includes.h b/tests/includes.h index 5f4a96b2..5d844a05 100644 --- a/tests/includes.h +++ b/tests/includes.h @@ -12,4 +12,5 @@ #include "../include/spdlog/spdlog.h" #include "../include/spdlog/sinks/null_sink.h" +#include "../include/spdlog/sinks/ostream_sink.h"