#pragma once #include #include #include "logging/log.hpp" #include "logging/levels.hpp" class Logger { template class Message : public Log::Record { public: Message(Timestamp timestamp, std::string location, std::string message) : timestamp(timestamp), location(location), message(message) {} const Timestamp& when() const override { return timestamp; } const std::string& where() const override { return location; } unsigned level() const override { return Level::level; } const std::string& level_str() const override { return Level::text; } const std::string& text() const override { return message; } private: Timestamp timestamp; std::string location; std::string message; }; public: Logger() = default; Logger(Log* log, const std::string& name) : log(log), name(name) {} template void emit(Args&&... args) { assert(log != nullptr); auto message = std::make_unique>( Timestamp::now(), name, fmt::format(std::forward(args)...) ); log->emit(std::move(message)); } template void trace(Args&&... args) { #ifndef NDEBUG #ifndef LOG_NO_TRACE emit(std::forward(args)...); #endif #endif } template void debug(Args&&... args) { #ifndef LOG_NO_DEBUG emit(std::forward(args)...); #endif } template void info(Args&&... args) { #ifndef LOG_NO_INFO emit(std::forward(args)...); #endif } template void warn(Args&&... args) { #ifndef LOG_NO_WARN emit(std::forward(args)...); #endif } template void error(Args&&... args) { #ifndef LOG_NO_ERROR emit(std::forward(args)...); #endif } private: Log* log; std::string name; };