mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 09:08:20 +00:00
Hooking into the Logging Framework.
This commit is contained in:
parent
a699470145
commit
e755bf1b54
2 changed files with 71 additions and 5 deletions
62
testing/btest/doc/manual/framework_logging_factorial_04.bro
Normal file
62
testing/btest/doc/manual/framework_logging_factorial_04.bro
Normal file
|
@ -0,0 +1,62 @@
|
|||
# @TEST-EXEC: bro %INPUT
|
||||
# @TEST-EXEC: btest-diff factor-mod5.log
|
||||
# @TEST-EXEC: btest-diff factor-non5.log
|
||||
|
||||
module Factor;
|
||||
|
||||
export {
|
||||
redef enum Log::ID += { LOG };
|
||||
|
||||
type Info: record {
|
||||
num: count &log;
|
||||
factorial_num: count &log;
|
||||
};
|
||||
|
||||
global log_factor: event(rec: Info);
|
||||
}
|
||||
|
||||
function factorial(n: count): count
|
||||
{
|
||||
if ( n == 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( n * factorial(n - 1) );
|
||||
}
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Log::create_stream(LOG, [$columns=Info, $ev=log_factorial]);
|
||||
}
|
||||
|
||||
event bro_done()
|
||||
{
|
||||
local numbers: vector of count = vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||
for ( n in numbers )
|
||||
{
|
||||
Log::write( Factor::LOG, [$num=numbers[n],
|
||||
$factorial_num=factorial(numbers[n])]);
|
||||
}
|
||||
}
|
||||
|
||||
function mod5(id: Log::ID, path: string, rec: Factor::Info) : string
|
||||
{
|
||||
if ( rec$factorial_num % 5 == 0 )
|
||||
{
|
||||
return "factor-mod5";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "factor-non5";
|
||||
}
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local filter: Log::Filter = [$name="split-mod5s", $path_func=mod5];
|
||||
Log::add_filter(Factor::LOG, filter);
|
||||
Log::remove_filter(Factor::LOG, "default");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue