Skip to content

Commit db756ce

Browse files
committed
fix: fix logger.setFile #323
1 parent bc50c70 commit db756ce

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/legacy/api/LoggerAPI.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "api/PlayerAPI.h"
55
#include "engine/EngineOwnData.h"
66
#include "ll/api/data/IndirectValue.h"
7+
#include "ll/api/io/DefaultSink.h"
78
#include "ll/api/io/FileSink.h"
89
#include "ll/api/io/Logger.h"
910
#include "ll/api/io/PatternFormatter.h"
@@ -166,7 +167,18 @@ Local<Value> LoggerClass::setFile(const Arguments& args) {
166167
if (args.size() >= 2) {
167168
sink->setFlushLevel(static_cast<LogLevel>(args[1].asNumber().toInt32() - 1));
168169
}
169-
return Boolean::newBoolean(getEngineOwnData()->logger->addSink(sink));
170+
bool hasFileSink = false;
171+
for (auto& sk : getEngineOwnData()->logger->sinks()) {
172+
if (typeid(sk) == typeid(ll::io::FileSink)) {
173+
hasFileSink = true;
174+
}
175+
}
176+
auto logger = getEngineOwnData()->logger;
177+
if (hasFileSink) {
178+
logger->clearSink();
179+
logger->addSink(std::make_shared<ll::io::DefaultSink>());
180+
}
181+
return Boolean::newBoolean(logger->addSink(sink));
170182
}
171183
CATCH("Fail in LoggerSetFile!")
172184
}

0 commit comments

Comments
 (0)