Fixed bugs in stdout_sinks and in msvc
This commit is contained in:
@@ -5,26 +5,27 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/details/console_globals.h"
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/details/traits.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <spdlog/details/console_globals.h>
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
namespace sinks {
|
||||
|
||||
template<class StdoutTrait, class ConsoleMutexTrait>
|
||||
template<class TargetStream, class ConsoleMutex>
|
||||
class stdout_sink : public sink
|
||||
{
|
||||
public:
|
||||
using mutex_t = typename ConsoleMutexTrait::mutex_t;
|
||||
using mutex_t = typename ConsoleMutex::mutex_t;
|
||||
stdout_sink()
|
||||
: mutex_(ConsoleMutexTrait::console_mutex())
|
||||
, file_(StdoutTrait::stream())
|
||||
: mutex_(ConsoleMutex::console_mutex())
|
||||
, file_(TargetStream::stream())
|
||||
{
|
||||
}
|
||||
~stdout_sink() = default;
|
||||
@@ -35,14 +36,16 @@ public:
|
||||
void log(const details::log_msg &msg) override
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), file_);
|
||||
fflush(StdoutTrait::stream());
|
||||
fmt::memory_buffer formatted;
|
||||
formatter_->format(msg, formatted);
|
||||
fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
|
||||
fflush(TargetStream::stream());
|
||||
}
|
||||
|
||||
void flush() override
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(StdoutTrait::stream());
|
||||
fflush(TargetStream::stream());
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -50,10 +53,11 @@ private:
|
||||
FILE *file_;
|
||||
};
|
||||
|
||||
using stdout_sink_mt = stdout_sink<details::console_stdout_trait, details::console_mutex_trait>;
|
||||
using stdout_sink_st = stdout_sink<details::console_stdout_trait, details::console_null_mutex_trait>;
|
||||
using stderr_sink_mt = stdout_sink<details::console_stderr_trait, details::console_mutex_trait>;
|
||||
using stderr_sink_st = stdout_sink<details::console_stderr_trait, details::console_null_mutex_trait>;
|
||||
using stdout_sink_mt = stdout_sink<details::console_stdout_stream, details::console_global_mutex>;
|
||||
using stdout_sink_st = stdout_sink<details::console_stdout_stream, details::console_global_nullmutex>;
|
||||
|
||||
using stderr_sink_mt = stdout_sink<details::console_stderr_stream, details::console_global_mutex>;
|
||||
using stderr_sink_st = stdout_sink<details::console_stderr_stream, details::console_global_nullmutex>;
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
|
||||
Reference in New Issue
Block a user