diff --git a/include/log_utils.h b/include/log_utils.h index d06000395..5d1932f85 100644 --- a/include/log_utils.h +++ b/include/log_utils.h @@ -121,7 +121,8 @@ public: /** * @brief Flushes the buffer to an output file stream. * - * Writes the entire contents of the buffer to the provided file stream and resets the buffer. + * Writes the entire contents of the buffer to the provided file stream. + * The caller is responsible for resetting the buffer after flushing. * * @param logfile The output file stream to write to. */ diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index 0e96150c4..88f01c012 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -1355,6 +1355,7 @@ void MySQL_Logger::events_open_log_unlocked() { metaEvent.write(&log_ctx->events, nullptr); log_ctx->events.flush_to_file(events.logfile); events.current_log_size += log_ctx->events.size(); + log_ctx->events.reset(monotonic_time()); } } catch (const std::ofstream::failure&) { diff --git a/lib/PgSQL_Logger.cpp b/lib/PgSQL_Logger.cpp index 426bc659d..5e6f93054 100644 --- a/lib/PgSQL_Logger.cpp +++ b/lib/PgSQL_Logger.cpp @@ -1028,7 +1028,6 @@ void PgSQL_Logger::flush() { const uint64_t current_time = monotonic_time(); // eventslog - bool flush_eventslog = false; if (is_events_logfile_open()) { if (log_ctx->events.size() > 0 && (current_time - log_ctx->events.get_last_flush_time()) > static_cast(pgsql_thread___eventslog_flush_timeout) * 1000) { @@ -1046,7 +1045,6 @@ void PgSQL_Logger::flush() { } // auditlogs - bool flush_auditlog = false; if (is_audit_logfile_open()) { if (log_ctx->audit.size() > 0 && (current_time - log_ctx->audit.get_last_flush_time()) > static_cast(pgsql_thread___auditlog_flush_timeout) * 1000) { diff --git a/lib/log_utils.cpp b/lib/log_utils.cpp index 0550fb0be..d78ac157f 100644 --- a/lib/log_utils.cpp +++ b/lib/log_utils.cpp @@ -94,11 +94,11 @@ bool flush_and_rotate( buffer.flush_to_file(logfile); current_log_size += buffer.size(); flushed = true; + logfile->flush(); if (current_log_size > max_log_file_size && rotate_fn) { rotate_fn(); current_log_size = 0; } - logfile->flush(); } unlock_fn(); if (flushed) {