| |
| |
| |
| |
|
|
| #pragma once |
|
|
| #include <string> |
| #include <format> |
| #include <iostream> |
| #include <chrono> |
| #include <source_location> |
|
|
| namespace app::utils { |
|
|
| enum class LogLevel { |
| Debug, |
| Info, |
| Warn, |
| Error |
| }; |
|
|
| class Logger { |
| public: |
| explicit Logger(std::string name) : name_(std::move(name)) {} |
|
|
| template<typename... Args> |
| void info(std::format_string<Args...> fmt, Args&&... args, |
| std::source_location loc = std::source_location::current()) { |
| log(LogLevel::Info, std::format(fmt, std::forward<Args>(args)...), loc); |
| } |
|
|
| template<typename... Args> |
| void error(std::format_string<Args...> fmt, Args&&... args, |
| std::source_location loc = std::source_location::current()) { |
| log(LogLevel::Error, std::format(fmt, std::forward<Args>(args)...), loc); |
| } |
|
|
| template<typename... Args> |
| void debug(std::format_string<Args...> fmt, Args&&... args, |
| std::source_location loc = std::source_location::current()) { |
| log(LogLevel::Debug, std::format(fmt, std::forward<Args>(args)...), loc); |
| } |
|
|
| private: |
| void log(LogLevel level, const std::string& message, const std::source_location& loc); |
|
|
| std::string name_; |
| }; |
|
|
| Logger& get_logger(const std::string& name); |
|
|
| } |
|
|