1
0
mirror of synced 2024-11-24 15:50:16 +01:00

sys: Disable buffering on log files

This commit is contained in:
WerWolv 2022-03-01 00:03:28 +01:00
parent 5a02c38fcd
commit b57730c28b
3 changed files with 14 additions and 5 deletions

View File

@ -61,6 +61,8 @@ namespace hex {
auto getHandle() { return this->m_file; }
const fs::path &getPath() { return this->m_path; }
void disableBuffering();
private:
FILE *m_file;
fs::path m_path;

View File

@ -42,7 +42,7 @@ namespace hex {
void File::close() {
if (isValid()) {
fclose(this->m_file);
std::fclose(this->m_file);
this->m_file = nullptr;
}
}
@ -83,19 +83,19 @@ namespace hex {
void File::write(const u8 *buffer, size_t size) {
if (!isValid()) return;
fwrite(buffer, size, 1, this->m_file);
std::fwrite(buffer, size, 1, this->m_file);
}
void File::write(const std::vector<u8> &bytes) {
if (!isValid()) return;
fwrite(bytes.data(), 1, bytes.size(), this->m_file);
std::fwrite(bytes.data(), 1, bytes.size(), this->m_file);
}
void File::write(const std::string &string) {
if (!isValid()) return;
fwrite(string.data(), string.size(), 1, this->m_file);
std::fwrite(string.data(), string.size(), 1, this->m_file);
}
size_t File::getSize() const {
@ -119,7 +119,7 @@ namespace hex {
}
void File::flush() {
fflush(this->m_file);
std::fflush(this->m_file);
}
bool File::remove() {
@ -127,4 +127,10 @@ namespace hex {
return std::remove(this->m_path.string().c_str()) == 0;
}
void File::disableBuffering() {
if (!isValid()) return;
std::setvbuf(this->m_file, nullptr, _IONBF, 0);
}
}

View File

@ -26,6 +26,7 @@ namespace hex::log {
for (const auto &path : hex::getPath(ImHexPath::Logs, true)) {
fs::create_directories(path);
g_loggerFile = File(path / hex::format("{0:%Y%m%d_%H%M%S}.log", fmt::localtime(std::chrono::system_clock::now())), File::Mode::Create);
g_loggerFile.disableBuffering();
if (g_loggerFile.isValid()) break;
}