Logging: Add BiF to flush all logs

This commit is contained in:
Jan Grashoefer 2025-10-13 19:20:34 +02:00
parent 5227e7ebb9
commit ccab1a91bf
5 changed files with 15 additions and 5 deletions

View file

@ -47,7 +47,7 @@ public:
explicit LogFlushWriteBufferTimer(double t) : Timer(t, zeek::detail::TIMER_LOG_FLUSH_WRITE_BUFFER) {} explicit LogFlushWriteBufferTimer(double t) : Timer(t, zeek::detail::TIMER_LOG_FLUSH_WRITE_BUFFER) {}
void Dispatch(double t, bool is_expire) override { void Dispatch(double t, bool is_expire) override {
zeek::log_mgr->FlushAllWriteBuffers(); zeek::log_mgr->FlushAll();
if ( ! is_expire ) if ( ! is_expire )
zeek::log_mgr->StartLogFlushTimer(); zeek::log_mgr->StartLogFlushTimer();
@ -2265,7 +2265,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con
return result; return result;
} }
void Manager::FlushAllWriteBuffers() { void Manager::FlushAll() {
for ( const auto* s : zeek::log_mgr->streams ) { for ( const auto* s : zeek::log_mgr->streams ) {
if ( ! s ) // may store nullptr if ( ! s ) // may store nullptr
continue; continue;

View file

@ -339,6 +339,11 @@ public:
*/ */
bool Flush(EnumVal* id); bool Flush(EnumVal* id);
/**
* Flushes all log streams including all associated writers.
*/
void FlushAll();
/** /**
* Signals the manager to shutdown at Zeek's termination. * 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 FinishedRotation(WriterFrontend* writer, const char* new_name, const char* old_name, double open, double close,
bool success, bool terminating); bool success, bool terminating);
// Flush write buffers of all writers.
void FlushAllWriteBuffers();
// Start the regular log flushing timer. // Start the regular log flushing timer.
void StartLogFlushTimer(); void StartLogFlushTimer();

View file

@ -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 function Log::__delay%(id: Log::ID, rec: any, post_delay_cb: PostDelayCallback%): Log::DelayToken
%{ %{
auto idptr = enum_ref(id); auto idptr = enum_ref(id);

View file

@ -107,6 +107,7 @@ static std::unordered_map<std::string, unsigned int> func_attrs = {
{"Log::__disable_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Log::__disable_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS},
{"Log::__enable_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Log::__enable_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS},
{"Log::__flush", 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::__get_delay_queue_size", ATTR_NO_ZEEK_SIDE_EFFECTS},
{"Log::__remove_filter", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Log::__remove_filter", ATTR_NO_SCRIPT_SIDE_EFFECTS},
{"Log::__remove_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS}, {"Log::__remove_stream", ATTR_NO_SCRIPT_SIDE_EFFECTS},

View file

@ -136,6 +136,7 @@ global known_BiFs = set(
"Log::__disable_stream", "Log::__disable_stream",
"Log::__enable_stream", "Log::__enable_stream",
"Log::__flush", "Log::__flush",
"Log::flush_all",
"Log::__get_delay_queue_size", "Log::__get_delay_queue_size",
"Log::__remove_filter", "Log::__remove_filter",
"Log::__remove_stream", "Log::__remove_stream",