41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
|
|
#pragma once
|
|
|
|
#if !defined(MIJIN_LOGGING_STDIO_SINK_HPP_INCLUDED)
|
|
#define MIJIN_LOGGING_STDIO_SINK_HPP_INCLUDED 1
|
|
|
|
#include "./formatting.hpp"
|
|
|
|
namespace mijin
|
|
{
|
|
template<template<typename> typename TAllocator = std::allocator,
|
|
deleter_type<LogFormatter<TAllocator<char>>> TDeleter = AllocatorDeleter<TAllocator<LogFormatter<TAllocator<char>>>>>
|
|
requires(allocator_type<TAllocator<char>>)
|
|
class StdioSink : public FormattingLogSink<TAllocator, TDeleter>
|
|
{
|
|
public:
|
|
using base_t = FormattingLogSink<TAllocator, TDeleter>;
|
|
using typename base_t::formatter_ptr_t;
|
|
|
|
explicit StdioSink(not_null_t<formatter_ptr_t> formatter, TAllocator<char> allocator = {})
|
|
MIJIN_NOEXCEPT_IF(std::is_nothrow_move_constructible_v<TAllocator<char>>)
|
|
: base_t(std::move(formatter), std::move(allocator)) {}
|
|
|
|
void handleMessageFormatted(const LogMessage& message, const char* formatted) MIJIN_NOEXCEPT override
|
|
{
|
|
if (*message.level >= mijin_log_level::WARNING)
|
|
{
|
|
std::fputs(formatted, stderr);
|
|
std::fputc('\n', stderr);
|
|
}
|
|
else
|
|
{
|
|
std::puts(formatted);
|
|
}
|
|
}
|
|
};
|
|
} // namespace mijin
|
|
|
|
|
|
#endif // !defined(MIJIN_LOGGING_STDIO_SINK_HPP_INCLUDED)
|