Logging: added default formatter and makeLogFormatter() utility function.
This commit is contained in:
parent
759174ed57
commit
ced73e43af
@ -64,6 +64,15 @@ MIJIN_DEFINE_CHAR_VERSIONS_TMPL(SimpleLogFormatter, FORMATTER_COMMON_ARGS, FORMA
|
||||
#undef FORMATTER_COMMON_ARGS
|
||||
#undef FORMATTER_SET_ARGS
|
||||
|
||||
template<typename TChar, typename TTraits, typename TAllocator, typename TFormatter = BaseSimpleLogFormatter<TChar, TTraits, TAllocator>>
|
||||
DynamicPointer<TFormatter> makeLogFormatter(typename TFormatter::string_t&& format)
|
||||
{
|
||||
return makeDynamic<TFormatter>(std::move(format));
|
||||
}
|
||||
|
||||
template<typename TChar, typename TTraits, typename TAllocator, typename TFormatter = BaseSimpleLogFormatter<TChar, TTraits, TAllocator>>
|
||||
inline TFormatter DEFAULT_FORMATTER("[{level}] {text}");
|
||||
|
||||
#define MIJIN_FORMATTING_SINK_COMMON_ARGS(chr_type) \
|
||||
typename TTraits = std::char_traits<chr_type>, \
|
||||
template<typename> typename TAllocator = MIJIN_DEFAULT_ALLOCATOR, \
|
||||
@ -95,10 +104,11 @@ private:
|
||||
formatter_ptr_t mFormatter;
|
||||
string_t mBuffer;
|
||||
public:
|
||||
explicit BaseFormattingLogSink(formatter_ptr_t formatter, allocator_t allocator = {})
|
||||
explicit BaseFormattingLogSink(formatter_ptr_t formatter = wrapDynamic(&DEFAULT_FORMATTER<char_t, traits_t, allocator_t>), allocator_t allocator = {})
|
||||
MIJIN_NOEXCEPT_IF(std::is_nothrow_move_constructible_v<allocator_t>)
|
||||
: mFormatter(std::move(formatter)), mBuffer(std::move(allocator))
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
virtual void handleMessageFormatted(const message_t& message, const string_t& formatted) MIJIN_NOEXCEPT = 0;
|
||||
|
||||
|
||||
@ -9,6 +9,9 @@
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
template<typename TChar, typename TTraits, typename TAllocator, typename TFormatter = BaseSimpleLogFormatter<TChar, TTraits, TAllocator>>
|
||||
inline TFormatter DEFAULT_STDIO_FORMATTER("[{ansi:level_color}{level}{ansi:reset}] {text} <{file}:{line}>");
|
||||
|
||||
template<MIJIN_FORMATTING_SINK_TMPL_ARGS_INIT>
|
||||
requires(allocator_type<TAllocator<TChar>>)
|
||||
class BaseStdioSink : public BaseFormattingLogSink<MIJIN_FORMATTING_SINK_TMP_ARG_NAMES>
|
||||
@ -16,6 +19,7 @@ class BaseStdioSink : public BaseFormattingLogSink<MIJIN_FORMATTING_SINK_TMP_ARG
|
||||
public:
|
||||
using base_t = BaseFormattingLogSink<MIJIN_FORMATTING_SINK_TMP_ARG_NAMES>;
|
||||
using typename base_t::char_t;
|
||||
using typename base_t::traits_t;
|
||||
using typename base_t::allocator_t;
|
||||
using typename base_t::formatter_ptr_t;
|
||||
using typename base_t::message_t;
|
||||
@ -23,7 +27,7 @@ public:
|
||||
private:
|
||||
int mMinStderrLevel = MIJIN_LOG_LEVEL_VALUE_WARNING;
|
||||
public:
|
||||
explicit BaseStdioSink(formatter_ptr_t formatter, allocator_t allocator = {})
|
||||
explicit BaseStdioSink(formatter_ptr_t formatter = wrapDynamic(&DEFAULT_STDIO_FORMATTER<char_t, traits_t, allocator_t>), allocator_t allocator = {})
|
||||
MIJIN_NOEXCEPT_IF(std::is_nothrow_move_constructible_v<allocator_t>)
|
||||
: base_t(std::move(formatter), std::move(allocator)) {}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user