Adam Macdonald a8d8b9b9ab
All checks were successful
Build (Arch Linux) / build (push) Successful in 3m10s
initial commit
2025-04-16 01:58:29 +01:00

68 lines
1.7 KiB
C++

#pragma once
#include <memory>
#include <string_view> // TODO: Use std::format_string when available
#include <utility>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
namespace kuiper
{
class logger {
public:
logger()
: m_log(spdlog::stdout_color_st("log")) {
#if !defined(NDEBUG)
m_log->set_level(spdlog::level::debug);
#else
m_log->set_level(spdlog::level::info);
#endif
}
logger(const char* name)
: m_log(spdlog::stdout_color_st(name)) {
#if !defined(NDEBUG)
m_log->set_level(spdlog::level::debug);
#else
m_log->set_level(spdlog::level::info);
#endif
}
~logger() = default;
template<typename... Args>
inline void trace(std::string_view fmt, Args&&... args) {
m_log->trace(fmt, std::forward<Args>(args)...);
}
template<typename... Args>
inline void debug(std::string_view fmt, Args&&... args) {
m_log->debug(fmt, std::forward<Args>(args)...);
}
template<typename... Args>
inline void info(std::string_view fmt, Args&&... args) {
m_log->info(fmt, std::forward<Args>(args)...);
}
template<typename... Args>
inline void warn(std::string_view fmt, Args&&... args) {
m_log->warn(fmt, std::forward<Args>(args)...);
}
template<typename... Args>
inline void error(std::string_view fmt, Args&&... args) {
m_log->error(fmt, std::forward<Args>(args)...);
}
template<typename... Args>
inline void critical(std::string_view fmt, Args&&... args) {
m_log->critical(fmt, std::forward<Args>(args)...);
}
private:
std::shared_ptr<spdlog::logger> m_log {nullptr};
};
} // namespace kuiper