kanidm/src/lib/log.rs

82 lines
1.8 KiB
Rust
Raw Normal View History

2018-09-29 09:54:16 +02:00
use actix::prelude::*;
2018-11-11 22:59:09 +01:00
2018-12-27 06:22:03 +01:00
use super::audit::AuditScope;
2018-09-29 09:54:16 +02:00
// Helper for internal logging.
2018-12-29 10:56:03 +01:00
// Should only be used at startup/shutdown
#[macro_export]
macro_rules! log_event {
($log_addr:expr, $($arg:tt)*) => ({
use log::LogEvent;
use std::fmt;
$log_addr.do_send(
LogEvent {
msg: fmt::format(
format_args!($($arg)*)
)
}
)
})
}
2018-09-29 09:54:16 +02:00
// We need to pass in config for this later
// Or we need to pass in the settings for it IE level and dest?
// Is there an efficent way to set a log level filter in the macros
// so that we don't msg unless it's the correct level?
// Do we need config in the log macro?
2018-09-29 09:54:16 +02:00
pub fn start() -> actix::Addr<EventLog> {
SyncArbiter::start(1, move || EventLog {})
2018-09-29 09:54:16 +02:00
}
pub struct EventLog {}
2018-09-29 09:54:16 +02:00
impl Actor for EventLog {
type Context = SyncContext<Self>;
2018-11-25 23:15:16 +01:00
/*
fn started(&mut self, ctx: &mut Self::Context) {
ctx.set_mailbox_capacity(1 << 31);
}
*/
2018-09-29 09:54:16 +02:00
}
// What messages can we be sent. Basically this is all the possible
// inputs we *could* recieve.
// Add a macro for easy msg write
pub struct LogEvent {
pub msg: String,
}
impl Message for LogEvent {
type Result = ();
}
impl Handler<LogEvent> for EventLog {
type Result = ();
fn handle(&mut self, event: LogEvent, _: &mut SyncContext<Self>) -> Self::Result {
println!("LOGEVENT: {}", event.msg);
2018-09-29 09:54:16 +02:00
}
}
2018-12-27 06:22:03 +01:00
impl Handler<AuditScope> for EventLog {
2018-11-11 22:59:09 +01:00
type Result = ();
2018-12-27 06:22:03 +01:00
fn handle(&mut self, event: AuditScope, _: &mut SyncContext<Self>) -> Self::Result {
2018-12-29 10:56:03 +01:00
println!("AUDIT: {}", event);
2018-11-11 22:59:09 +01:00
}
}
/*
2018-09-29 09:54:16 +02:00
impl Handler<Event> for EventLog {
type Result = ();
fn handle(&mut self, event: Event, _: &mut SyncContext<Self>) -> Self::Result {
println!("EVENT: {:?}", event)
}
}
*/