Fix 2265: close tui on success, custom tui subscriber (#2734)

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-07-31 10:49:51 -07:00
1 parent 189772a17b
commit 63e7aab4e8
10 files changed
+226 -54

No files matched your search

+3 -25
View File
@@ -6,6 +6,7 @@ pub mod assets;
pub mod dx_build_info;
pub mod serve;
pub mod tools;
pub mod tracer;
pub mod cli;
pub use cli::*;
@@ -23,21 +24,16 @@ pub(crate) use settings::*;
pub(crate) mod metadata;
use std::env;
use tracing_subscriber::{prelude::*, EnvFilter, Layer};
use anyhow::Context;
use clap::Parser;
use Commands::*;
const LOG_ENV: &str = "DIOXUS_LOG";
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Cli::parse();
build_tracing();
let log_control = tracer::build_tracing();
match args.action {
Translate(opts) => opts
@@ -79,7 +75,7 @@ async fn main() -> anyhow::Result<()> {
.context(error_wrapper("Cleaning project failed")),
Serve(opts) => opts
.serve()
.serve(log_control)
.await
.context(error_wrapper("Serving project failed")),
@@ -94,21 +90,3 @@ async fn main() -> anyhow::Result<()> {
fn error_wrapper(message: &str) -> String {
format!("🚫 {message}:")
}
fn build_tracing() {
// If {LOG_ENV} is set, default to env, otherwise filter to cli
// and manganis warnings and errors from other crates
let mut filter = EnvFilter::new("error,dx=info,dioxus-cli=info,manganis-cli-support=info");
if env::var(LOG_ENV).is_ok() {
filter = EnvFilter::from_env(LOG_ENV);
}
let sub =
tracing_subscriber::registry().with(tracing_subscriber::fmt::layer().with_filter(filter));
#[cfg(feature = "tokio-console")]
sub.with(console_subscriber::spawn()).init();
#[cfg(not(feature = "tokio-console"))]
sub.init();
}