Console is attached and compiles

This commit is contained in:
Nadja Reitzenstein
2022-06-21 22:23:55 +02:00
parent 35c9f45f6d
commit 287ca9806d
13 changed files with 2008 additions and 372 deletions

View File

@ -76,7 +76,7 @@ pub static RESOURCES: OnceCell<ResourcesHandle> = OnceCell::new();
impl Diflouroborane {
pub fn new(config: Config) -> miette::Result<Self> {
logging::init(&config.logging);
let mut server = logging::init(&config.logging);
tracing::info!(version = env::VERSION, "Starting BFFH");
let span = tracing::info_span!("setup");
@ -84,6 +84,11 @@ impl Diflouroborane {
let executor = Executor::new();
if let Some(aggregator) = server.aggregator.take() {
executor.spawn(aggregator.run());
}
executor.spawn(server.serve());
let env = StateDB::open_env(&config.db_path)?;
let statedb = StateDB::create_with_env(env.clone())?;

View File

@ -1,6 +1,7 @@
use tracing_subscriber::EnvFilter;
use serde::{Deserialize, Serialize};
use tracing_subscriber::prelude::*;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogConfig {
@ -24,21 +25,25 @@ impl Default for LogConfig {
}
}
pub fn init(config: &LogConfig) {
pub fn init(config: &LogConfig) -> console::Server {
let (console, server) = console::ConsoleLayer::new();
let filter = if let Some(ref filter) = config.filter {
EnvFilter::new(filter.as_str())
} else {
EnvFilter::from_env("BFFH_LOG")
};
let builder = tracing_subscriber::fmt().with_env_filter(filter);
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();
match format.as_str() {
"compact" => builder.compact().init(),
"pretty" => builder.pretty().init(),
"full" => builder.init(),
_ => builder.init(),
}
tracing::info!(format = format.as_str(), "Logging initialized")
tracing_subscriber::registry()
.with(fmt_layer)
.with(console)
.init();
tracing::info!(format = format.as_str(), "Logging initialized");
server
}