-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlogger.h
23 lines (18 loc) · 943 Bytes
/
logger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once
// This is a snippet you can put at the top of all of your SKSE plugins!
#include <spdlog/sinks/basic_file_sink.h>
namespace logger = SKSE::log;
void SetupLog() {
auto logsFolder = SKSE::log::log_directory();
if (!logsFolder) SKSE::stl::report_and_fail("SKSE log_directory not provided, logs disabled.");
auto pluginName = SKSE::PluginDeclaration::GetSingleton()->GetName();
auto logFilePath = *logsFolder / std::format("{}.log", pluginName);
auto fileLoggerPtr = std::make_shared<spdlog::sinks::basic_file_sink_mt>(logFilePath.string(), true);
auto loggerPtr = std::make_shared<spdlog::logger>("log", std::move(fileLoggerPtr));
spdlog::set_default_logger(std::move(loggerPtr));
spdlog::set_level(spdlog::level::trace);
spdlog::flush_on(spdlog::level::trace);
}
// Then just call SetupLog() in your SKSE plugin initialization
//
// ^---- don't forget to do this or your logs won't work :)