From ccab1a91bf8168eb54d0dda8b1de62c4939cbcaa Mon Sep 17 00:00:00 2001 From: Jan Grashoefer Date: Mon, 13 Oct 2025 19:20:34 +0200 Subject: [PATCH] Logging: Add BiF to flush all logs --- src/logging/Manager.cc | 4 ++-- src/logging/Manager.h | 8 +++++--- src/logging/logging.bif | 6 ++++++ src/script_opt/FuncInfo.cc | 1 + testing/btest/opt/ZAM-bif-tracking.zeek | 1 + 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 0c8b777808..073c8050f7 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -47,7 +47,7 @@ public: explicit LogFlushWriteBufferTimer(double t) : Timer(t, zeek::detail::TIMER_LOG_FLUSH_WRITE_BUFFER) {} void Dispatch(double t, bool is_expire) override { - zeek::log_mgr->FlushAllWriteBuffers(); + zeek::log_mgr->FlushAll(); if ( ! is_expire ) zeek::log_mgr->StartLogFlushTimer(); @@ -2265,7 +2265,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con return result; } -void Manager::FlushAllWriteBuffers() { +void Manager::FlushAll() { for ( const auto* s : zeek::log_mgr->streams ) { if ( ! s ) // may store nullptr continue; diff --git a/src/logging/Manager.h b/src/logging/Manager.h index 84a5013c82..9099bb6d67 100644 --- a/src/logging/Manager.h +++ b/src/logging/Manager.h @@ -339,6 +339,11 @@ public: */ bool Flush(EnumVal* id); + /** + * Flushes all log streams including all associated writers. + */ + void FlushAll(); + /** * Signals the manager to shutdown at Zeek's termination. */ @@ -391,9 +396,6 @@ protected: bool FinishedRotation(WriterFrontend* writer, const char* new_name, const char* old_name, double open, double close, bool success, bool terminating); - // Flush write buffers of all writers. - void FlushAllWriteBuffers(); - // Start the regular log flushing timer. void StartLogFlushTimer(); diff --git a/src/logging/logging.bif b/src/logging/logging.bif index b76f083ab4..e04e39c596 100644 --- a/src/logging/logging.bif +++ b/src/logging/logging.bif @@ -99,6 +99,12 @@ namespace } %%} +function Log::flush_all%(%): any + %{ + zeek::log_mgr->FlushAll(); + return nullptr; + %} + function Log::__delay%(id: Log::ID, rec: any, post_delay_cb: PostDelayCallback%): Log::DelayToken %{ auto idptr = enum_ref(id); diff --git a/src/script_opt/FuncInfo.cc b/src/script_opt/FuncInfo.cc index f7e0cf791e..a9cbe67971 100644 --- a/src/script_opt/FuncInfo.cc +++ b/src/script_opt/FuncInfo.cc @@ -107,6 +107,7 @@ static std::unordered_map func_attrs = { {"Log::__disable_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Log::__enable_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Log::__flush", ATTR_NO_SCRIPT_SIDE_EFFECTS}, + {"Log::flush_all", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Log::__get_delay_queue_size", ATTR_NO_ZEEK_SIDE_EFFECTS}, {"Log::__remove_filter", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Log::__remove_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS}, diff --git a/testing/btest/opt/ZAM-bif-tracking.zeek b/testing/btest/opt/ZAM-bif-tracking.zeek index ac9c148fa0..7f8c8a42a5 100644 --- a/testing/btest/opt/ZAM-bif-tracking.zeek +++ b/testing/btest/opt/ZAM-bif-tracking.zeek @@ -136,6 +136,7 @@ global known_BiFs = set( "Log::__disable_stream", "Log::__enable_stream", "Log::__flush", + "Log::flush_all", "Log::__get_delay_queue_size", "Log::__remove_filter", "Log::__remove_stream",