use crate::session::session_id::SessionID;
use composite_log::{CompositeLog, CompositeLogFactory};
use enum_dispatch::enum_dispatch;
use file_log::{FileLog, FileLogFactory};
#[cfg(feature = "mongo_log")]
use mongo_log::{MongoLog, MongoLogFactory};
use null_log::{NullLog, NullLogFactory};
#[cfg(feature = "otel_log")]
use otel_log::{OtelLog, OtelLogFactory};
use screen_log::{ScreenLog, ScreenLogFactory};
#[cfg(feature = "sql_log")]
use sql_log::{SqlLog, SqlLogFactory};
use rustc_hash::FxHashMap;
use std::sync::Arc;
pub mod composite_log;
pub mod file_log;
#[cfg(feature = "mongo_log")]
pub mod mongo_log;
pub mod null_log;
#[cfg(feature = "otel_log")]
pub mod otel_log;
pub mod screen_log;
#[cfg(feature = "sql_log")]
pub mod sql_log;
#[allow(async_fn_in_trait)] #[enum_dispatch]
pub trait LogTrait {
async fn on_incoming(&mut self, data: &[u8]);
async fn on_outgoing(&mut self, data: &[u8]);
async fn on_event(&mut self, data: &str);
async fn on_eventf(&mut self, format: &str, params: FxHashMap<String, String>);
}
#[allow(async_fn_in_trait)] #[enum_dispatch]
pub trait LogFactoryTrait {
async fn create(&mut self) -> Result<LogEnum, String>;
async fn create_session_log(&mut self, session_id: Arc<SessionID>) -> Result<LogEnum, String>;
}
#[enum_dispatch(LogTrait)]
pub enum LogEnum {
NullLog,
ScreenLog,
FileLog,
CompositeLog,
#[cfg(feature = "mongo_log")]
MongoLog,
#[cfg(feature = "otel_log")]
OtelLog,
#[cfg(feature = "sql_log")]
SqlLog,
}
impl Default for LogEnum {
fn default() -> Self {
Self::NullLog(NullLog)
}
}
#[enum_dispatch(LogFactoryTrait)]
#[derive(Clone)]
pub enum LogFactoryEnum {
NullLogFactory,
ScreenLogFactory,
FileLogFactory,
CompositeLogFactory,
#[cfg(feature = "mongo_log")]
MongoLogFactory,
#[cfg(feature = "otel_log")]
OtelLogFactory,
#[cfg(feature = "sql_log")]
SqlLogFactory,
}
impl Default for LogFactoryEnum {
fn default() -> Self {
Self::NullLogFactory(NullLogFactory)
}
}