-
I've implemented my own custom flag |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Adding padding seems to be the role of the formatter. spdlog/include/spdlog/pattern_formatter-inl.h Lines 138 to 153 in 76fb40d spdlog/include/spdlog/pattern_formatter-inl.h Lines 1397 to 1404 in 76fb40d For custom formatters, it appears that spdlog/include/spdlog/pattern_formatter-inl.h Lines 1096 to 1104 in 76fb40d spdlog/include/spdlog/pattern_formatter.h Lines 71 to 75 in 76fb40d So adding padding in the custom formatting function should work. Example (NOTE has not been tested): #include "spdlog/pattern_formatter.h"
class my_formatter_flag : public spdlog::custom_flag_formatter
{
public:
void format(const spdlog::details::log_msg &, const std::tm &, spdlog::memory_buf_t &dest) override
{
std::string some_txt = "custom-flag";
if (this->padinfo_.enabled())
{
spdlog::details::scoped_padder(some_txt.size(), this->padinfo_, dest);
}
dest.append(some_txt.data(), some_txt.data() + some_txt.size());
}
std::unique_ptr<custom_flag_formatter> clone() const override
{
return spdlog::details::make_unique<my_formatter_flag>();
}
}; |
Beta Was this translation helpful? Give feedback.
Adding padding seems to be the role of the formatter.
As far as I can tell from the source of the
short_level_formatter
, it passespadding_info
toScopedPadder
to add padding.The
ScopedPadder
is passed as a template argument, eitherscoped_padder
ornull_scoped_padder
.spdlog/include/spdlog/pattern_formatter-inl.h
Lines 138 to 153 in 76fb40d