diff --git a/Cargo.lock b/Cargo.lock index f01992f..cc70b38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -992,6 +992,7 @@ dependencies = [ "inventory", "lazy_static", "libc", + "lightproc", "linkme", "lmdb-rkv", "miette", diff --git a/Cargo.toml b/Cargo.toml index fdae5ba..581c6bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ dirs = "4.0.0" # Runtime executor = { path = "runtime/executor" } +lightproc = { path = "runtime/lightproc" } console = { path = "runtime/console" } # Catch&Handle POSIX process signals diff --git a/bffhd/audit.rs b/bffhd/audit.rs index 35f0340..0bf135c 100644 --- a/bffhd/audit.rs +++ b/bffhd/audit.rs @@ -10,6 +10,7 @@ use serde_json::Serializer; pub static AUDIT: OnceCell = OnceCell::new(); +// TODO: Make the audit log a tracing layer #[derive(Debug)] pub struct AuditLog { writer: Mutex>, diff --git a/bffhd/lib.rs b/bffhd/lib.rs index f0b60c7..422813a 100644 --- a/bffhd/lib.rs +++ b/bffhd/lib.rs @@ -61,9 +61,11 @@ use crate::tls::TlsConfig; use crate::users::db::UserDB; use crate::users::Users; use executor::pool::Executor; +use lightproc::recoverable_handle::RecoverableHandle; use signal_hook::consts::signal::*; use tracing::Span; + pub struct Diflouroborane { config: Config, executor: Executor<'static>, @@ -82,6 +84,9 @@ impl error::Description for SignalHandlerErr { } impl Diflouroborane { + pub fn setup() { + } + pub fn new(config: Config) -> miette::Result { let mut server = logging::init(&config.logging); let span = tracing::info_span!( @@ -189,3 +194,18 @@ impl Diflouroborane { Ok(()) } } + +struct ShutdownHandler { + tasks: Vec>, +} +impl ShutdownHandler { + pub fn new(tasks: Vec>) -> Self { + Self { tasks } + } + + pub fn shutdown(&mut self) { + for handle in self.tasks.drain(..) { + handle.cancel() + } + } +} \ No newline at end of file diff --git a/bffhd/logging.rs b/bffhd/logging.rs index 51d9832..8e7f100 100644 --- a/bffhd/logging.rs +++ b/bffhd/logging.rs @@ -1,7 +1,9 @@ -use tracing_subscriber::EnvFilter; - +use std::path::Path; +use tracing_subscriber::{EnvFilter, reload}; use serde::{Deserialize, Serialize}; +use tracing_subscriber::fmt::format::Format; use tracing_subscriber::prelude::*; +use tracing_subscriber::reload::Handle; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct LogConfig { @@ -25,8 +27,22 @@ impl Default for LogConfig { } } +pub enum LogOutput<'a> { + Journald, + Stdout, + File(&'a Path), +} +pub struct LogConfig2<'a, F> { + output: LogOutput<'a>, + filter_str: Option<&'a str>, + format: Format +} + pub fn init(config: &LogConfig) -> console::Server { - let (console, server) = console::ConsoleLayer::new(); + let subscriber = tracing_subscriber::registry(); + + let (console_layer, server) = console::ConsoleLayer::new(); + let subscriber = subscriber.with(console_layer); let filter = if let Some(ref filter) = config.filter { EnvFilter::new(filter.as_str()) @@ -34,14 +50,29 @@ pub fn init(config: &LogConfig) -> console::Server { EnvFilter::from_env("BFFH_LOG") }; - let format = &config.format; - // TODO: Restore output format settings being settable - let fmt_layer = tracing_subscriber::fmt::layer().with_filter(filter); + let format = config.format.to_lowercase(); - tracing_subscriber::registry() - .with(fmt_layer) - .with(console) - .init(); + let fmt_layer = tracing_subscriber::fmt::layer(); + + match format.as_ref() { + "pretty" => { + let fmt_layer = fmt_layer + .pretty() + .with_filter(filter); + subscriber.with(fmt_layer).init(); + } + "compact" => { + let fmt_layer = fmt_layer + .compact() + .with_filter(filter); + subscriber.with(fmt_layer).init(); + } + _ => { + let fmt_layer = fmt_layer + .with_filter(filter); + subscriber.with(fmt_layer).init(); + } + } tracing::info!(format = format.as_str(), "Logging initialized");