mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-12-22 03:33:48 +01:00
Fix log format settings
This commit is contained in:
parent
70c94feced
commit
218a316571
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -992,6 +992,7 @@ dependencies = [
|
||||
"inventory",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"lightproc",
|
||||
"linkme",
|
||||
"lmdb-rkv",
|
||||
"miette",
|
||||
|
@ -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
|
||||
|
@ -10,6 +10,7 @@ use serde_json::Serializer;
|
||||
|
||||
pub static AUDIT: OnceCell<AuditLog> = OnceCell::new();
|
||||
|
||||
// TODO: Make the audit log a tracing layer
|
||||
#[derive(Debug)]
|
||||
pub struct AuditLog {
|
||||
writer: Mutex<LineWriter<File>>,
|
||||
|
20
bffhd/lib.rs
20
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<Self> {
|
||||
let mut server = logging::init(&config.logging);
|
||||
let span = tracing::info_span!(
|
||||
@ -189,3 +194,18 @@ impl Diflouroborane {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct ShutdownHandler {
|
||||
tasks: Vec<RecoverableHandle<()>>,
|
||||
}
|
||||
impl ShutdownHandler {
|
||||
pub fn new(tasks: Vec<RecoverableHandle<()>>) -> Self {
|
||||
Self { tasks }
|
||||
}
|
||||
|
||||
pub fn shutdown(&mut self) {
|
||||
for handle in self.tasks.drain(..) {
|
||||
handle.cancel()
|
||||
}
|
||||
}
|
||||
}
|
@ -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<F>
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user