Deep logging support

This commit is contained in:
MetricExpansion 2022-10-09 14:07:31 -07:00
parent 6d5ac0ea14
commit fbcd0ebbaa
7 changed files with 46 additions and 9 deletions

View file

@ -171,11 +171,17 @@ add_custom_command(TARGET SkyrimOutfitSystemSE POST_BUILD
find_package(span-lite REQUIRED CONFIG)
find_package(spdlog REQUIRED CONFIG)
find_package(xbyak REQUIRED CONFIG)
find_library(INIH_LIBRARY inih REQUIRED)
find_path(INIH_INCLUDE_DIRS "ini.h" REQUIRED)
target_link_libraries(SkyrimOutfitSystemSE PUBLIC
CommonLibSSE::CommonLibSSE
nonstd::span-lite
spdlog::spdlog
${INIH_LIBRARY}
ProtocolBuffers
xbyak::xbyak
)
target_include_directories(SkyrimOutfitSystemSE PRIVATE
${INIH_INCLUDE_DIRS})

View file

@ -13,6 +13,8 @@
#include <REL/Relocation.h>
#include <SKSE/SKSE.h>
#include "INIReader.h"
#ifdef NDEBUG
#include <spdlog/sinks/basic_file_sink.h>
#else

View file

@ -5,3 +5,11 @@
std::string GetRuntimeName();
const std::string& GetRuntimeDirectory();
class Settings {
public:
Settings();
~Settings();
INIReader reader;
static Settings* Instance();
};

View file

@ -29,6 +29,7 @@ namespace OutfitSystem {
std::int32_t GetOutfitNameMaxLength(RE::BSScript::IVirtualMachine* registry,
std::uint32_t stackId,
RE::StaticFunctionTag*) {
LOG(trace, "GetOutfitNameMaxLength");
return ArmorAddonOverrideService::ce_outfitNameMaxLength;
}
std::vector<RE::TESObjectARMO*> GetCarriedArmor(RE::BSScript::IVirtualMachine* registry,

View file

@ -50,3 +50,22 @@ const std::string& GetRuntimeDirectory() {
return s_runtimeDirectory;
}
Settings::Settings() : reader(GetRuntimeDirectory() + "Data\\SKSE\\Plugins\\SkyrimOutfitSystemSE.ini") {
if (reader.ParseError() != 0) {
// Failed to load INI. We proceed without it.
LOG(info, "Could not load INI file from {}. Continuing without it.", GetRuntimeDirectory() + "Data\\SKSE\\Plugins\\SkyrimOutfitSystemSE.ini");
return;
} else {
LOG(info, "INI file was successfully loaded.");
}
}
Settings::~Settings() {}
static Settings* settings;
Settings* Settings::Instance() {
if (!settings) settings = new Settings();
return settings;
}

View file

@ -1,9 +1,8 @@
#include "OutfitSystem.h"
#include <ShlObj.h>
#include <ArmorAddonOverrideService.h>
#include <hooking/Hooks.hpp>
#include "ArmorAddonOverrideService.h"
#include "hooking/Hooks.hpp"
#include "Utility.h"
void WaitForDebugger(void) {
while (!IsDebuggerPresent()) {
@ -28,11 +27,12 @@ namespace {
*path /= fmt::format("{}.log"sv, Plugin::NAME);
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true);
#ifndef NDEBUG
const auto level = spdlog::level::trace;
#else
const auto level = spdlog::level::info;
#endif
auto level = spdlog::level::info;
bool deepLogEnabled = Settings::Instance()->reader.GetBoolean("Debug", "ExtraLogging", false);
if (deepLogEnabled) {
LOG(info, "Extra logging enabled.");
level = spdlog::level::trace;
}
auto log = std::make_shared<spdlog::logger>("global log"s, std::move(sink));
log->set_level(level);

View file

@ -6,6 +6,7 @@
"dependencies": [
"span-lite",
"spdlog",
"inih",
"protobuf",
"boost-stl-interfaces",
"rsm-binary-io",