mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 06:47:56 +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",
|
"inventory",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
|
"lightproc",
|
||||||
"linkme",
|
"linkme",
|
||||||
"lmdb-rkv",
|
"lmdb-rkv",
|
||||||
"miette",
|
"miette",
|
||||||
|
@ -49,6 +49,7 @@ dirs = "4.0.0"
|
|||||||
|
|
||||||
# Runtime
|
# Runtime
|
||||||
executor = { path = "runtime/executor" }
|
executor = { path = "runtime/executor" }
|
||||||
|
lightproc = { path = "runtime/lightproc" }
|
||||||
console = { path = "runtime/console" }
|
console = { path = "runtime/console" }
|
||||||
|
|
||||||
# Catch&Handle POSIX process signals
|
# Catch&Handle POSIX process signals
|
||||||
|
@ -10,6 +10,7 @@ use serde_json::Serializer;
|
|||||||
|
|
||||||
pub static AUDIT: OnceCell<AuditLog> = OnceCell::new();
|
pub static AUDIT: OnceCell<AuditLog> = OnceCell::new();
|
||||||
|
|
||||||
|
// TODO: Make the audit log a tracing layer
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AuditLog {
|
pub struct AuditLog {
|
||||||
writer: Mutex<LineWriter<File>>,
|
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::db::UserDB;
|
||||||
use crate::users::Users;
|
use crate::users::Users;
|
||||||
use executor::pool::Executor;
|
use executor::pool::Executor;
|
||||||
|
use lightproc::recoverable_handle::RecoverableHandle;
|
||||||
use signal_hook::consts::signal::*;
|
use signal_hook::consts::signal::*;
|
||||||
use tracing::Span;
|
use tracing::Span;
|
||||||
|
|
||||||
|
|
||||||
pub struct Diflouroborane {
|
pub struct Diflouroborane {
|
||||||
config: Config,
|
config: Config,
|
||||||
executor: Executor<'static>,
|
executor: Executor<'static>,
|
||||||
@ -82,6 +84,9 @@ impl error::Description for SignalHandlerErr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Diflouroborane {
|
impl Diflouroborane {
|
||||||
|
pub fn setup() {
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(config: Config) -> miette::Result<Self> {
|
pub fn new(config: Config) -> miette::Result<Self> {
|
||||||
let mut server = logging::init(&config.logging);
|
let mut server = logging::init(&config.logging);
|
||||||
let span = tracing::info_span!(
|
let span = tracing::info_span!(
|
||||||
@ -189,3 +194,18 @@ impl Diflouroborane {
|
|||||||
Ok(())
|
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 serde::{Deserialize, Serialize};
|
||||||
|
use tracing_subscriber::fmt::format::Format;
|
||||||
use tracing_subscriber::prelude::*;
|
use tracing_subscriber::prelude::*;
|
||||||
|
use tracing_subscriber::reload::Handle;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct LogConfig {
|
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 {
|
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 {
|
let filter = if let Some(ref filter) = config.filter {
|
||||||
EnvFilter::new(filter.as_str())
|
EnvFilter::new(filter.as_str())
|
||||||
@ -34,14 +50,29 @@ pub fn init(config: &LogConfig) -> console::Server {
|
|||||||
EnvFilter::from_env("BFFH_LOG")
|
EnvFilter::from_env("BFFH_LOG")
|
||||||
};
|
};
|
||||||
|
|
||||||
let format = &config.format;
|
let format = config.format.to_lowercase();
|
||||||
// TODO: Restore output format settings being settable
|
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer().with_filter(filter);
|
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
let fmt_layer = tracing_subscriber::fmt::layer();
|
||||||
.with(fmt_layer)
|
|
||||||
.with(console)
|
match format.as_ref() {
|
||||||
.init();
|
"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");
|
tracing::info!(format = format.as_str(), "Logging initialized");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user