Unified usage of fmt::memory_buffer across the codebase

This commit is contained in:
gabime
2019-08-28 18:46:09 +03:00
parent c2efd6ee58
commit f5492aed12
29 changed files with 123 additions and 126 deletions

View File

@@ -40,7 +40,7 @@ protected:
void sink_it_(const details::log_msg &msg) override
{
const android_LogPriority priority = convert_to_android_(msg.level);
fmt::memory_buffer formatted;
memory_buf_t formatted;
if (use_raw_msg_)
{
details::fmt_helper::append_string_view(msg.payload, formatted);

View File

@@ -44,7 +44,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::log(const details::log_msg &msg
// If color is not supported in the terminal, log as is instead.
std::lock_guard<mutex_t> lock(mutex_);
fmt::memory_buffer formatted;
memory_buf_t formatted;
formatter_->format(msg, formatted);
if (should_do_colors_ && msg.color_range_end > msg.color_range_start)
{
@@ -115,7 +115,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_ccode_(const string_view_
}
template<typename ConsoleMutex>
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end)
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end)
{
fwrite(formatted.data() + start, sizeof(char), end - start, target_file_);
}

View File

@@ -82,7 +82,7 @@ private:
std::unique_ptr<spdlog::formatter> formatter_;
std::unordered_map<level::level_enum, string_view_t, level::level_hasher> colors_;
void print_ccode_(const string_view_t &color_code);
void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end);
void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
};
template<typename ConsoleMutex>

View File

@@ -28,7 +28,7 @@ SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const
template<typename Mutex>
SPDLOG_INLINE void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
{
fmt::memory_buffer formatted;
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
file_helper_.write(formatted);
}

View File

@@ -30,7 +30,7 @@ struct daily_filename_calculator
{
filename_t basename, ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
std::conditional<std::is_same<filename_t::value_type, char>::value, fmt::memory_buffer, fmt::wmemory_buffer>::type w;
std::conditional<std::is_same<filename_t::value_type, char>::value, memory_buf_t, fmt::wmemory_buffer>::type w;
fmt::format_to(
w, SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, ext);
return fmt::to_string(w);
@@ -78,7 +78,7 @@ protected:
file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(time)), truncate_);
rotation_tp_ = next_rotation_tp_();
}
fmt::memory_buffer formatted;
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
file_helper_.write(formatted);
}

View File

@@ -66,7 +66,7 @@ protected:
// log the "skipped.." message
if (skip_counter_ > 0)
{
fmt::basic_memory_buffer<char, 64> buf;
memory_buf_t buf;
fmt::format_to(buf, "Skipped {} duplicate messages..", skip_counter_);
details::log_msg skipped_msg{msg.logger_name, msg.level, string_view_t{buf.data(), buf.size()}};
dist_sink<Mutex>::sink_it_(skipped_msg);

View File

@@ -28,7 +28,7 @@ protected:
void sink_it_(const details::log_msg &msg) override
{
fmt::memory_buffer formatted;
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
OutputDebugStringA(fmt::to_string(formatted).c_str());
}

View File

@@ -25,7 +25,7 @@ public:
protected:
void sink_it_(const details::log_msg &msg) override
{
fmt::memory_buffer formatted;
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
ostream_.write(formatted.data(), static_cast<std::streamsize>(formatted.size()));
if (force_flush_)

View File

@@ -43,7 +43,7 @@ SPDLOG_INLINE rotating_file_sink<Mutex>::rotating_file_sink(
template<typename Mutex>
SPDLOG_INLINE filename_t rotating_file_sink<Mutex>::calc_filename(const filename_t &filename, std::size_t index)
{
typename std::conditional<std::is_same<filename_t::value_type, char>::value, fmt::memory_buffer, fmt::wmemory_buffer>::type w;
typename std::conditional<std::is_same<filename_t::value_type, char>::value, memory_buf_t, fmt::wmemory_buffer>::type w;
if (index != 0u)
{
filename_t basename, ext;
@@ -66,7 +66,7 @@ SPDLOG_INLINE const filename_t &rotating_file_sink<Mutex>::filename() const
template<typename Mutex>
SPDLOG_INLINE void rotating_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
{
fmt::memory_buffer formatted;
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
current_size_ += formatted.size();
if (current_size_ > max_size_)

View File

@@ -26,7 +26,7 @@ template<typename ConsoleMutex>
SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg)
{
std::lock_guard<mutex_t> lock(mutex_);
fmt::memory_buffer formatted;
memory_buf_t formatted;
formatter_->format(msg, formatted);
fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
fflush(file_); // flush every line to terminal

View File

@@ -50,7 +50,7 @@ protected:
if (enable_formatting_)
{
fmt::memory_buffer formatted;
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
payload = string_view_t(formatted.data(), formatted.size());
}

View File

@@ -52,7 +52,7 @@ template<typename ConsoleMutex>
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
{
std::lock_guard<mutex_t> lock(mutex_);
fmt::memory_buffer formatted;
memory_buf_t formatted;
formatter_->format(msg, formatted);
if (!in_console_)
{
@@ -131,14 +131,14 @@ WORD SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_foreground_color_(WORD attri
// print a range of formatted message to console
template<typename ConsoleMutex>
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end)
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end)
{
auto size = static_cast<DWORD>(end - start);
::WriteConsoleA(out_handle_, formatted.data() + start, size, nullptr, nullptr);
}
template<typename ConsoleMutex>
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const fmt::memory_buffer &formatted)
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_t &formatted)
{
auto size = static_cast<DWORD>(formatted.size());
if (size == 0)

View File

@@ -58,10 +58,10 @@ protected:
WORD set_foreground_color_(WORD attribs);
// print a range of formatted message to console
void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end);
void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
// in case we are redirected to file (not in console mode)
void write_to_file_(const fmt::memory_buffer &formatted);
void write_to_file_(const memory_buf_t &formatted);
};
template<typename ConsoleMutex>