mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-01 10:59:02 +08:00
Added padding support and set_pattern to custom_flags
This commit is contained in:
@@ -1024,8 +1024,9 @@ SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory
|
||||
details::fmt_helper::append_string_view(eol_, dest);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void pattern_formatter::recompile()
|
||||
SPDLOG_INLINE void pattern_formatter::set_pattern(std::string pattern)
|
||||
{
|
||||
pattern_ = std::move(pattern);
|
||||
compile_pattern_(pattern_);
|
||||
}
|
||||
|
||||
@@ -1041,15 +1042,19 @@ SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg)
|
||||
template<typename Padder>
|
||||
SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding)
|
||||
{
|
||||
// process custom flags
|
||||
auto it = custom_handlers_.find(flag);
|
||||
if (it != custom_handlers_.end())
|
||||
if (it != custom_handlers_.end())
|
||||
{
|
||||
formatters_.push_back(it->second->clone());
|
||||
auto custom_handler = it->second->clone();
|
||||
custom_handler->set_padding_info(padding);
|
||||
formatters_.push_back(std::move(custom_handler));
|
||||
return;
|
||||
}
|
||||
switch (flag)
|
||||
{
|
||||
|
||||
// process built-in flags
|
||||
switch (flag)
|
||||
{
|
||||
case ('+'): // default formatter
|
||||
formatters_.push_back(details::make_unique<details::full_formatter>(padding));
|
||||
break;
|
||||
|
@@ -41,8 +41,8 @@ struct padding_info
|
||||
{
|
||||
return enabled_;
|
||||
}
|
||||
const size_t width_ = 0;
|
||||
const pad_side side_ = left;
|
||||
size_t width_ = 0;
|
||||
pad_side side_ = left;
|
||||
bool truncate_ = false;
|
||||
bool enabled_ = false;
|
||||
};
|
||||
@@ -67,6 +67,11 @@ class SPDLOG_API custom_flag_formatter : public details::flag_formatter
|
||||
{
|
||||
public:
|
||||
virtual std::unique_ptr<custom_flag_formatter> clone() const = 0;
|
||||
|
||||
void set_padding_info(details::padding_info padding)
|
||||
{
|
||||
flag_formatter::padinfo_ = padding;
|
||||
}
|
||||
};
|
||||
|
||||
class SPDLOG_API pattern_formatter final : public formatter
|
||||
@@ -92,7 +97,7 @@ public:
|
||||
custom_handlers_[flag] = details::make_unique<T>(args...);
|
||||
return *this;
|
||||
}
|
||||
void recompile();
|
||||
void set_pattern(std::string pattern);
|
||||
|
||||
private:
|
||||
std::string pattern_;
|
||||
|
Reference in New Issue
Block a user