Skip to content

Commit 4b95e42

Browse files
committed
feat: add rotating log option
1 parent 5ad461e commit 4b95e42

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

include/SKSE/API.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace SKSE
2222
#endif
2323
const char* logName{ nullptr };
2424
const char* logPattern{ nullptr };
25+
std::size_t logRotate{ 0 };
2526
bool trampoline{ false };
2627
std::size_t trampolineSize{ 0 };
2728
bool hook{ true };

src/SKSE/API.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <spdlog/sinks/basic_file_sink.h>
77
#include <spdlog/sinks/msvc_sink.h>
8+
#include <spdlog/sinks/rotating_file_sink.h>
89
#include <spdlog/spdlog.h>
910

1011
namespace SKSE
@@ -99,10 +100,16 @@ namespace SKSE
99100
*path /= std::format("{}.log", info.logName ? info.logName : SKSE::GetPluginName());
100101

101102
std::vector<spdlog::sink_ptr> sinks{
102-
std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true),
103103
std::make_shared<spdlog::sinks::msvc_sink_mt>()
104104
};
105105

106+
if (info.logRotate > 0) {
107+
constexpr auto maxSize = std::numeric_limits<std::size_t>::max();
108+
sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(path->string(), maxSize, info.logRotate, true));
109+
} else {
110+
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true));
111+
}
112+
106113
auto logger = std::make_shared<spdlog::logger>("global", sinks.begin(), sinks.end());
107114
logger->set_level(static_cast<spdlog::level::level_enum>(info.logLevel));
108115
logger->flush_on(static_cast<spdlog::level::level_enum>(info.logLevel));

0 commit comments

Comments
 (0)