mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 11:29:01 +08:00
wip static-lib
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
#include "spdlog/sinks/base_sink.h"
|
||||
#include "spdlog/details/os.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "spdlog/details/console_globals.h"
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/details/pattern_formatter.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
@@ -7,8 +7,8 @@ namespace spdlog {
|
||||
namespace sinks {
|
||||
template<typename TargetStream, typename ConsoleMutex>
|
||||
SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::wincolor_sink()
|
||||
: out_handle_(TargetStream::handle())
|
||||
, mutex_(ConsoleMutex::mutex())
|
||||
: out_handle_(TargetStream::handle())
|
||||
, mutex_(ConsoleMutex::mutex())
|
||||
{
|
||||
colors_[level::trace] = WHITE;
|
||||
colors_[level::debug] = CYAN;
|
||||
@@ -49,7 +49,7 @@ void SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::log(const details:
|
||||
print_range_(formatted, msg.color_range_start, msg.color_range_end);
|
||||
::SetConsoleTextAttribute(out_handle_,
|
||||
orig_attribs); // reset to orig colors
|
||||
// after color range
|
||||
// after color range
|
||||
print_range_(formatted, msg.color_range_end, formatted.size());
|
||||
}
|
||||
else // print without colors if color range is invalid
|
||||
@@ -77,7 +77,7 @@ void SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::set_formatter(std:
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
|
||||
|
||||
// set color and return the orig console attributes (for resetting later)
|
||||
template<typename TargetStream, typename ConsoleMutex>
|
||||
WORD SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::set_console_attribs(WORD attribs)
|
||||
@@ -100,5 +100,5 @@ void SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::print_range_(const
|
||||
::WriteConsoleA(out_handle_, formatted.data() + start, size, nullptr, nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
@@ -35,27 +35,26 @@ public:
|
||||
const WORD WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
const WORD YELLOW = FOREGROUND_RED | FOREGROUND_GREEN;
|
||||
|
||||
wincolor_sink();
|
||||
wincolor_sink();
|
||||
~wincolor_sink() override;
|
||||
|
||||
wincolor_sink(const wincolor_sink &other) = delete;
|
||||
wincolor_sink &operator=(const wincolor_sink &other) = delete;
|
||||
|
||||
// change the color for the given level
|
||||
void set_color(level::level_enum level, WORD color);
|
||||
void log(const details::log_msg &msg) final override;
|
||||
void flush() final override;
|
||||
void set_pattern(const std::string &pattern) override final;
|
||||
void set_color(level::level_enum level, WORD color);
|
||||
void log(const details::log_msg &msg) final override;
|
||||
void flush() final override;
|
||||
void set_pattern(const std::string &pattern) override final;
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override final;
|
||||
|
||||
|
||||
private:
|
||||
using mutex_t = typename ConsoleMutex::mutex_t;
|
||||
using mutex_t = typename ConsoleMutex::mutex_t;
|
||||
HANDLE out_handle_;
|
||||
mutex_t &mutex_;
|
||||
std::unordered_map<level::level_enum, WORD, level::level_hasher> colors_;
|
||||
|
||||
// set color and return the orig console attributes (for resetting later)
|
||||
// set color and return the orig console attributes (for resetting later)
|
||||
WORD set_console_attribs(WORD attribs);
|
||||
// print a range of formatted message to console
|
||||
void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end);
|
||||
|
Reference in New Issue
Block a user