From 5e4a1cbe5ba7e51f87f7d0c022513cb312dbad3a Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Tue, 13 Aug 2024 18:15:43 +0200 Subject: [PATCH] refactor(log): remove annoying INFO logs on linux --- Cargo.toml | 1 + src/app.rs | 26 ++++++++++++++++++-------- src/main.rs | 22 ++++++++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 595c499..7d3a00b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,4 @@ clap = { version = "4.5.15", features = ["derive"] } image = "0.25.2" rand = "0.8.5" rfd = "0.14.1" +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } diff --git a/src/app.rs b/src/app.rs index 8cf4136..d25d3c9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,7 @@ use clap::Parser; use egui::IconData; use libpt::cli::args::{VerbosityLevel, HELP_TEMPLATE}; -use libpt::log::{debug, trace}; +use libpt::log::trace; pub const TITLE: &str = "Rollator"; @@ -23,8 +23,9 @@ pub struct RollatorApp { #[command(flatten)] pub(crate) verbosity: VerbosityLevel, + /// open the informations window on start #[serde(skip)] - #[clap(skip)] + #[arg(short = 'i', long = "info")] show_info_window: bool, } @@ -64,9 +65,9 @@ impl RollatorApp { pub fn info_diag(&mut self, ctx: &egui::Context) { trace!("rendering info dialogue"); ctx.show_viewport_immediate( - egui::ViewportId::from_hash_of("immediate_viewport"), + egui::ViewportId::from_hash_of(format!("{TITLE}: Information")), egui::ViewportBuilder::default() - .with_title("Immediate Viewport") + .with_title(format!("{TITLE}: Information")) .with_inner_size([500.0, 200.0]), |ctx, class| { assert!( @@ -75,7 +76,6 @@ impl RollatorApp { ); egui::CentralPanel::default().show(ctx, |ui| { - ui.spacing_mut().item_spacing.x = 0.0; ui.label(format!("{TITLE} v{}", env!("CARGO_PKG_VERSION"))); ui.hyperlink_to("Source Code\n", env!("CARGO_PKG_REPOSITORY")); ui.label(format!("Author: {}", env!("CARGO_PKG_AUTHORS"))); @@ -86,7 +86,17 @@ impl RollatorApp { //////////////////////////////////////////////////////////////// - bottom_label(ui); + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 0.0; + ui.label("Powered by "); + ui.hyperlink_to("egui", "https://github.com/emilk/egui"); + ui.label(" and "); + ui.hyperlink_to( + "eframe", + "https://github.com/emilk/egui/tree/master/crates/eframe", + ); + ui.label("."); + }); //////////////////////////////////////////////////////////////// }); @@ -163,8 +173,8 @@ impl eframe::App for RollatorApp { fn bottom_label(ui: &mut egui::Ui) { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 0.0; - ui.hyperlink_to("Source Code ", env!("CARGO_PKG_REPOSITORY")); - ui.label("| Powered by "); + ui.label(format!("{TITLE} v{}", env!("CARGO_PKG_VERSION"))); + ui.label(" | Powered by "); ui.hyperlink_to("egui", "https://github.com/emilk/egui"); ui.label(" and "); ui.hyperlink_to( diff --git a/src/main.rs b/src/main.rs index 01c334b..833f53e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,26 @@ mod app; // When compiling natively: #[cfg(not(target_arch = "wasm32"))] fn main() -> eframe::Result { + use libpt::log::debug; + use tracing_subscriber::util::SubscriberInitExt; + let mut app = app::RollatorApp::new_with_cli(); - let _logger = libpt::log::Logger::builder() - .set_level(app.verbosity.level()) - .build() - .expect("could not init logging"); + let filter = tracing_subscriber::EnvFilter::builder() + .with_default_directive(tracing_subscriber::filter::LevelFilter::WARN.into()) + .from_env() + .expect("could not init logger") + .add_directive( + format!("rollator={}", app.verbosity.level()) + .parse() + .expect("could not init logger"), + ); + + tracing_subscriber::fmt::Subscriber::builder() + .with_env_filter(filter) + .finish() + .set_default(); + debug!("logging initialized!"); let native_options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default()