mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Move the log creation code to a header file
This commit is contained in:
parent
0743cce845
commit
18751a3728
@ -34,6 +34,8 @@ add_library(${PROJECT_NAME} SHARED
|
|||||||
|
|
||||||
"include/export.h"
|
"include/export.h"
|
||||||
|
|
||||||
|
"include/engine.hpp"
|
||||||
|
|
||||||
"include/log.hpp"
|
"include/log.hpp"
|
||||||
|
|
||||||
"include/window.hpp"
|
"include/window.hpp"
|
||||||
@ -80,7 +82,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE src)
|
|||||||
|
|
||||||
# Pass some project information into the source code
|
# Pass some project information into the source code
|
||||||
configure_file(config.h.in config.h)
|
configure_file(config.h.in config.h)
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
# libraries:
|
# libraries:
|
||||||
|
|
||||||
|
45
include/engine.hpp
Normal file
45
include/engine.hpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
#include "log.hpp"
|
||||||
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
|
||||||
|
// To be executed in the target application, NOT engine.dll
|
||||||
|
void setupLog(const char* appName)
|
||||||
|
{
|
||||||
|
|
||||||
|
const std::string LOG_FILENAME{ std::string(appName) + ".log"};
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
// RELEASE
|
||||||
|
const std::filesystem::path log_path{ std::filesystem::temp_directory_path() / LOG_FILENAME };
|
||||||
|
#else
|
||||||
|
// DEBUG
|
||||||
|
const std::filesystem::path log_path{ LOG_FILENAME };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::vector<spdlog::sink_ptr> sinks;
|
||||||
|
|
||||||
|
sinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(log_path.string(), true));
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
// DEBUG
|
||||||
|
sinks.emplace_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
auto logger = std::make_shared<spdlog::logger>("sdltest", sinks.begin(), sinks.end());
|
||||||
|
|
||||||
|
logger->set_level(spdlog::level::trace);
|
||||||
|
|
||||||
|
spdlog::register_logger(logger);
|
||||||
|
spdlog::set_default_logger(logger);
|
||||||
|
|
||||||
|
INFO("Created log with path: {}", log_path.string());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user