Improve the simple_filter macro
The simple_filter macro must accept the two different levels of contexts. In the same way, it should also accept the log level, and therefore replace the now removed simple_filter_log_level macro.
This commit is contained in:
parent
789a41b51e
commit
995c0c35c1
4 changed files with 46 additions and 22 deletions
|
@ -1,6 +1,11 @@
|
|||
use opensmtpd::entry::Entry;
|
||||
use opensmtpd::{report, simple_filter};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct MyContext {
|
||||
nb: usize,
|
||||
}
|
||||
|
||||
#[report(v1, smtp_in, match(all))]
|
||||
fn echo_handler(entry: &Entry) -> Result<(), String> {
|
||||
log::info!("TEST ENTRY: {:?}", entry);
|
||||
|
@ -14,5 +19,5 @@ fn test(entry: &Entry) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
simple_filter!(echo_handler, test);
|
||||
simple_filter!(MyContext, [echo_handler, test]);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use log;
|
||||
use opensmtpd::entry::Entry;
|
||||
use opensmtpd::{report, simple_filter};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
|
@ -5,12 +7,13 @@ struct MyContext {
|
|||
nb: usize,
|
||||
}
|
||||
|
||||
#[report(Any)]
|
||||
#[report(v1, smtp_in, match(all))]
|
||||
fn on_report(ctx: &mut MyContext, entry: &Entry) {
|
||||
ctx.nb += 1;
|
||||
info!("Event received: {}, {}", entry.get_session_id(), ctx.nb);
|
||||
log::info!("Event received: {}, {}", entry.get_session_id(), ctx.nb);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
simple_filter!(vec![on_report]);
|
||||
simple_filter!(MyContext, [on_report]);
|
||||
}
|
||||
|
|
Reference in a new issue