#pragma once #include #include #include #include #include #include namespace vl::logging { struct Logger : public std::enable_shared_from_this { virtual ~Logger() = default; virtual std::string_view prefix() const noexcept = 0; virtual void setLevel(Level) noexcept = 0; virtual Level level() const noexcept = 0; template void log(Level lvl, std::format_string fmt, Args&&... args) { if (lvl < level()) return; Message m; m.ts = std::chrono::system_clock::now(); m.level = lvl; m.prefix = std::string(prefix()); m.text = std::vformat(fmt.get(), std::make_format_args(std::forward(args)...)); enqueue(std::move(m)); } template void trace(std::format_string f, Args&&... a){ log(Level::Trace,f,std::forward(a)...); } template void debug(std::format_string f, Args&&... a){ log(Level::Debug,f,std::forward(a)...); } template void info (std::format_string f, Args&&... a){ log(Level::Info ,f,std::forward(a)...); } template void warn (std::format_string f, Args&&... a){ log(Level::Warn ,f,std::forward(a)...); } template void error(std::format_string f, Args&&... a){ log(Level::Error,f,std::forward(a)...); } protected: virtual void enqueue(Message&&) = 0; }; } // namespace vl::log