Added more stuff like Logging, DynamicPointer, utilities for using STL allocators and NotNullable.
This commit is contained in:
40
source/mijin/logging/stdio_sink.hpp
Normal file
40
source/mijin/logging/stdio_sink.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#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)
|
||||
Reference in New Issue
Block a user