default logger init
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
set(UTILSLIBNAME pixelariumutilslib)
|
||||
|
||||
set(UTILSLIBSRC
|
||||
SpdLogger.cpp)
|
||||
|
||||
add_library(${UTILSLIBNAME} STATIC ${UTILSLIBSRC})
|
||||
|
||||
target_include_directories(${UTILSLIBNAME}
|
||||
PRIVATE ${spdlog_DIR}/include)
|
||||
|
||||
target_link_libraries(${UTILSLIBNAME}
|
||||
PRIVATE spdlog::spdlog_header_only)
|
||||
@@ -6,16 +6,12 @@ namespace pixelarium::utils::log
|
||||
class ILog
|
||||
{
|
||||
public:
|
||||
virtual void Info(const std::string& msg,
|
||||
const std::string& source = "") = 0;
|
||||
virtual void Debug(const std::string& msg,
|
||||
const std::string& source = "") = 0;
|
||||
virtual void Warn(const std::string& msg,
|
||||
const std::string& source = "") = 0;
|
||||
virtual void Error(const std::string& msg,
|
||||
const std::string& source = "") = 0;
|
||||
virtual void Info(const std::string& msg) = 0;
|
||||
virtual void Debug(const std::string& msg) = 0;
|
||||
virtual void Warn(const std::string& msg) = 0;
|
||||
virtual void Error(const std::string& msg) = 0;
|
||||
|
||||
virtual ~ILog() {}
|
||||
};
|
||||
|
||||
} // namespace pixelarium::utils
|
||||
} // namespace pixelarium::utils::log
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "SpdLogger.hpp"
|
||||
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
||||
using namespace pixelarium::utils::log;
|
||||
|
||||
SpdLogger::SpdLogger(const std::string& file_sink, const std::string& name)
|
||||
: _logger(spdlog::basic_logger_mt(file_sink, name)), _file(file_sink), _name(name)
|
||||
{
|
||||
spdlog::set_default_logger(this->_logger);
|
||||
spdlog::flush_on(spdlog::level::info);
|
||||
_logger->info("Logger initiated");
|
||||
}
|
||||
|
||||
void SpdLogger::Info(const std::string& msg)
|
||||
{
|
||||
this->_logger->info(msg);
|
||||
}
|
||||
void SpdLogger::Debug(const std::string& msg)
|
||||
{
|
||||
this->_logger->debug(msg);
|
||||
}
|
||||
void SpdLogger::Warn(const std::string& msg)
|
||||
{
|
||||
this->_logger->warn(msg);
|
||||
}
|
||||
void SpdLogger::Error(const std::string& msg)
|
||||
{
|
||||
this->_logger->error(msg);
|
||||
}
|
||||
@@ -1,19 +1,26 @@
|
||||
#pragma once
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ILog.hpp"
|
||||
namespace pixelarium::utils::log
|
||||
{
|
||||
class SpdLogger : public ILog
|
||||
{
|
||||
public:
|
||||
SpdLogger(const std::string& file_sink);
|
||||
explicit SpdLogger(const std::string& file_sink, const std::string& name);
|
||||
|
||||
void Info(const std::string& msg,
|
||||
const std::string& source = "") override;
|
||||
void Debug(const std::string& msg,
|
||||
const std::string& source = "") override;
|
||||
void Warn(const std::string& msg,
|
||||
const std::string& source = "") override;
|
||||
void Error(const std::string& msg,
|
||||
const std::string& source = "") override;
|
||||
void Info(const std::string& msg) override;
|
||||
void Debug(const std::string& msg) override;
|
||||
void Warn(const std::string& msg) override;
|
||||
void Error(const std::string& msg) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<spdlog::logger> _logger;
|
||||
std::string _file;
|
||||
std::string _name;
|
||||
};
|
||||
} // namespace pixelarium::utils::log
|
||||
Reference in New Issue
Block a user