mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
logging: Better error messages for invalid Log::delay() calls
Add a test for Log::delay() usage within filter policy hooks, too.
This commit is contained in:
parent
5e046eee58
commit
e2ce929fa4
6 changed files with 29 additions and 7 deletions
|
@ -1190,12 +1190,13 @@ bool Manager::WriteToFilters(const Manager::Stream* stream, zeek::RecordValPtr c
|
||||||
|
|
||||||
ValPtr Manager::Delay(const EnumValPtr& id, const RecordValPtr record, FuncPtr post_delay_cb) {
|
ValPtr Manager::Delay(const EnumValPtr& id, const RecordValPtr record, FuncPtr post_delay_cb) {
|
||||||
if ( active_writes.size() == 0 ) {
|
if ( active_writes.size() == 0 ) {
|
||||||
reporter->Error("invalid Log::delay() call: no active write context available");
|
reporter->Error("invalid Log::delay() call: outside of Log::log_stream_policy() hook");
|
||||||
return make_intrusive<detail::LogDelayTokenVal>();
|
return make_intrusive<detail::LogDelayTokenVal>();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& active_write_ctx = active_writes.back();
|
const auto& active_write_ctx = active_writes.back();
|
||||||
if ( active_write_ctx.id != id || active_write_ctx.record != record ) {
|
if ( active_write_ctx.id != id || active_write_ctx.record != record ) {
|
||||||
reporter->Error("invalid Log::delay() call: active write mismatch");
|
reporter->Error("invalid Log::delay() call: argument mismatch with active Log::write()");
|
||||||
return make_intrusive<detail::LogDelayTokenVal>();
|
return make_intrusive<detail::LogDelayTokenVal>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
1362692527.080972 error: invalid Log::delay() call: active write mismatch
|
1362692527.080972 error: invalid Log::delay() call: argument mismatch with active Log::write()
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
1362692527.080972 error: invalid Log::delay() call: active write mismatch
|
1362692527.080972 error: invalid Log::delay() call: argument mismatch with active Log::write()
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
1362692527.080972 error: invalid Log::delay() call: outside of Log::log_stream_policy() hook
|
||||||
|
1362692527.080972 error: invalid Log::delay_finish() call: invalid token provided
|
|
@ -1,2 +1,3 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
error: invalid Log::delay() call: no active write context available
|
error: invalid Log::delay() call: outside of Log::log_stream_policy() hook
|
||||||
|
error: invalid Log::delay_finish() call: invalid token provided
|
||||||
|
|
|
@ -5,10 +5,17 @@
|
||||||
|
|
||||||
redef enum Log::ID += { LOG };
|
redef enum Log::ID += { LOG };
|
||||||
|
|
||||||
|
type Info: record {
|
||||||
|
ts: time &log &default=network_time();
|
||||||
|
};
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
{
|
{
|
||||||
# Not within a log write
|
# Log::delay() not within a Log::log_stream_policy hook
|
||||||
Log::delay(LOG, []);
|
Log::create_stream(LOG, [$columns=Info]);
|
||||||
|
local rec = Info();
|
||||||
|
local token = Log::delay(LOG, rec);
|
||||||
|
Log::delay_finish(LOG, rec, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TEST-START-NEXT
|
@TEST-START-NEXT
|
||||||
|
@ -50,3 +57,13 @@ hook Log::log_stream_policy(rec: Conn::Info, id: Log::ID)
|
||||||
Log::delay_finish(id, rec, token);
|
Log::delay_finish(id, rec, token);
|
||||||
Log::delay_finish(id, rec, token);
|
Log::delay_finish(id, rec, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TEST-START-NEXT
|
||||||
|
@load base/protocols/conn
|
||||||
|
|
||||||
|
hook Conn::log_policy(rec: Conn::Info, id: Log::ID, filter: Log::Filter)
|
||||||
|
{
|
||||||
|
# Calling Log::delay() in a filter policy hook is an error.
|
||||||
|
local token = Log::delay(id, rec);
|
||||||
|
Log::delay_finish(id, rec, token);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue