sys: Disable buffering on log files
This commit is contained in:
parent
5a02c38fcd
commit
b57730c28b
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user