[APP] Flush log & save config on quick exit
This commit is contained in:
@@ -65,6 +65,7 @@ DEFINE_int32(
|
||||
|
||||
namespace dp = disruptorplus;
|
||||
using namespace xe::literals;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace xe {
|
||||
|
||||
@@ -240,9 +241,15 @@ class Logger {
|
||||
sinks_.push_back(std::move(sink));
|
||||
}
|
||||
|
||||
void FlushAllSinks() {
|
||||
for (const auto& sink : sinks_) {
|
||||
sink->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr size_t kBufferSize = 8_MiB;
|
||||
uint8_t buffer_[kBufferSize];
|
||||
uint8_t buffer_[kBufferSize] = {};
|
||||
|
||||
static constexpr size_t kBlockSize = 256;
|
||||
static constexpr size_t kBlockCount = kBufferSize / kBlockSize;
|
||||
@@ -468,6 +475,15 @@ void ShutdownLogging() {
|
||||
memory::AlignedFree(logger);
|
||||
}
|
||||
|
||||
void FlushLog() {
|
||||
if (!logger_) {
|
||||
return;
|
||||
}
|
||||
|
||||
xe::threading::Sleep(10ms);
|
||||
logger_->FlushAllSinks();
|
||||
}
|
||||
|
||||
static int g_saved_loglevel = static_cast<int>(LogLevel::Disabled);
|
||||
void logging::ToggleLogLevel() {
|
||||
auto swap = g_saved_loglevel;
|
||||
|
||||
@@ -75,6 +75,7 @@ class DebugPrintLogSink final : public LogSink {
|
||||
// Must be called on startup.
|
||||
void InitializeLogging(const std::string_view app_name);
|
||||
void ShutdownLogging();
|
||||
void FlushLog();
|
||||
|
||||
namespace logging {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user