#pragma once #include #include #include "utils/datetime/timestamp.hpp" class Logger; class Log { public: using uptr = std::unique_ptr; class Record { public: using uptr = std::unique_ptr; Record() = default; virtual ~Record() = default; virtual const Timestamp& when() const = 0; virtual const std::string& where() const = 0; virtual unsigned level() const = 0; virtual const std::string& level_str() const = 0; virtual const std::string& text() const = 0; }; class Stream { public: using uptr = std::unique_ptr; Stream() = default; virtual ~Stream() = default; virtual void emit(const Record&) = 0; }; virtual ~Log() = default; Logger logger(const std::string& name); void pipe(Stream::uptr&& stream) { streams.emplace_back(std::forward(stream)); } protected: friend class Logger; virtual void emit(Record::uptr record) = 0; void dispatch(const Record& record) { for(auto& stream : streams) stream->emit(record); } std::vector streams; };