This commit is contained in:
56
include/logging/engine_logger.hpp
Normal file
56
include/logging/engine_logger.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "logging/logger.hpp"
|
||||
|
||||
namespace kuiper
|
||||
{
|
||||
|
||||
/// @brief Singleton class providing engine-wide logging facilities
|
||||
class engine_logger {
|
||||
private:
|
||||
engine_logger() = default;
|
||||
|
||||
public:
|
||||
~engine_logger() = default;
|
||||
|
||||
public:
|
||||
static inline engine_logger& get(void) {
|
||||
static engine_logger s_instance;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void trace(const char* fmt, Args... args) {
|
||||
m_log.trace(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void debug(const char* fmt, Args... args) {
|
||||
m_log.debug(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void info(const char* fmt, Args... args) {
|
||||
m_log.info(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void warn(const char* fmt, Args... args) {
|
||||
m_log.warn(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void error(const char* fmt, Args... args) {
|
||||
m_log.error(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void critical(const char* fmt, Args... args) {
|
||||
m_log.critical(fmt, args...);
|
||||
}
|
||||
|
||||
private:
|
||||
kuiper::logger m_log {"engine"};
|
||||
};
|
||||
|
||||
} // namespace kuiper
|
||||
67
include/logging/logger.hpp
Normal file
67
include/logging/logger.hpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user