tracing: improved logs output

- now launcher can use `RUST_LOG` variable to filter logs
- removed "called event" logs from wine/dxvk/progress bar components
Also:
- fixed constant "remove_css_class" gtk errors
This commit is contained in:
Observer KRypt0n_ 2023-02-23 14:14:06 +02:00
parent 4e6325dd4f
commit 1dcc1b5403
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
9 changed files with 71 additions and 56 deletions

28
Cargo.lock generated
View file

@ -46,6 +46,7 @@ dependencies = [
"serde_json",
"sysinfo",
"tar",
"tracing",
"xz",
"zip",
]
@ -79,6 +80,7 @@ dependencies = [
"md5",
"serde",
"serde_json",
"tracing",
"wincompatlib",
]
@ -1269,6 +1271,15 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata",
]
[[package]]
name = "md5"
version = "0.7.0"
@ -1649,6 +1660,15 @@ dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.28"
@ -1979,9 +1999,9 @@ dependencies = [
[[package]]
name = "sysinfo"
version = "0.27.1"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccb297c0afb439440834b4bcf02c5c9da8ec2e808e70f36b0d8e815ff403bd24"
checksum = "727220a596b4ca0af040a07091e49f5c105ec8f2592674339a5bf35be592f76e"
dependencies = [
"cfg-if",
"core-foundation-sys",
@ -2164,10 +2184,14 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
]

View file

@ -23,7 +23,7 @@ adw = { package = "libadwaita", version = "0.2", features = ["v1_2"] }
anime-launcher-sdk = { path = "anime-launcher-sdk" }
tracing = "0.1"
tracing-subscriber = "0.3"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
fluent-templates = "0.8"
unic-langid = "0.9"

@ -1 +1 @@
Subproject commit a62aeef9cd9caa0e147fddcf05f4c412c942b736
Subproject commit 2e726358a2a74af9f35a5c55ea3bc6e7025575ae

View file

@ -5,6 +5,7 @@ use anime_launcher_sdk::anime_game_core::prelude::*;
use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
use tracing_subscriber::prelude::*;
use tracing_subscriber::filter::*;
use std::path::PathBuf;
@ -40,33 +41,39 @@ lazy_static::lazy_static! {
}
fn main() {
let stdout = tracing_subscriber::fmt::layer().pretty();
// Force debug output
let force_debug = std::env::args().any(|arg| &arg == "--debug");
// Update RUST_LOG env variable if needed
if !std::env::vars().any(|(key, _)| key == "RUST_LOG") {
std::env::set_var("RUST_LOG", {
if APP_DEBUG || force_debug {
"trace"
} else {
"warn"
}
});
}
// Prepare stdout logger
let stdout = tracing_subscriber::fmt::layer()
.pretty()
.with_filter(EnvFilter::from_default_env());
// Prepare debug file logger
let file = match std::fs::File::create(DEBUG_FILE.as_path()) {
Ok(file) => file,
Err(error) => panic!("Failed to create debug.log file: {:?}", error)
};
let mut debug_log = tracing_subscriber::fmt::layer()
.with_writer(std::sync::Arc::new(file));
debug_log.set_ansi(false);
let debug_log = tracing_subscriber::fmt::layer()
.with_writer(std::sync::Arc::new(file))
.with_ansi(false)
.with_filter(EnvFilter::from_default_env());
tracing_subscriber::registry()
.with({
stdout
.with_filter(tracing_subscriber::filter::LevelFilter::from_level({
if APP_DEBUG || std::env::args().any(|arg| &arg == "--debug") {
tracing::Level::TRACE
} else {
tracing::Level::WARN
}
}))
.with_filter(tracing_subscriber::filter::filter_fn(|metadata| {
!metadata.target().starts_with("rustls")
}))
.and_then(debug_log)
})
.with(stdout)
.with(debug_log)
.init();
tracing::info!("Starting application");

View file

@ -61,8 +61,6 @@ impl SimpleAsyncComponent for ComponentGroup {
}
async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) {
tracing::debug!("Called component group [{}] event: {:?}", self.title, msg);
match msg {
AppMsg::ShowRecommendedOnly(state) => {
self.show_recommended_only = state;

View file

@ -66,8 +66,6 @@ impl<T: std::fmt::Debug + Clone + 'static> SimpleAsyncComponent for ComponentsLi
}
async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) {
tracing::debug!("Called components list event: {:?}", msg);
match msg {
AppMsg::ShowRecommendedOnly(state) => {
self.show_recommended_only = state;

View file

@ -110,8 +110,6 @@ impl SimpleAsyncComponent for ProgressBar {
}
async fn update(&mut self, msg: Self::Input, _sender: AsyncComponentSender<Self>) {
tracing::debug!("Called components list event: {:?}", msg);
match msg {
AppMsg::Reset => {
self.fraction = 0.0;

View file

@ -119,8 +119,6 @@ impl SimpleAsyncComponent for ComponentVersion {
}
async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) {
tracing::debug!("Called component version [{}] event: {:?} (state = {:?})", self.title, msg, self.state);
match msg {
AppMsg::ShowRecommendedOnly(state) => self.show_recommended_only = state,

View file

@ -103,21 +103,23 @@ impl SimpleComponent for App {
),
#[watch]
add_css_class: match model.style {
LauncherStyle::Modern => "",
set_css_classes: &{
let mut classes = vec!["background", "csd"];
if APP_DEBUG {
classes.push("devel");
}
match model.style {
LauncherStyle::Modern => (),
LauncherStyle::Classic => {
if model.loading.is_none() {
"classic-style"
} else {
""
classes.push("classic-style");
}
}
}
},
#[watch]
remove_css_class: match model.style {
LauncherStyle::Modern => "classic-style",
LauncherStyle::Classic => ""
classes
},
#[local_ref]
@ -127,15 +129,9 @@ impl SimpleComponent for App {
adw::HeaderBar {
#[watch]
add_css_class: match model.style {
LauncherStyle::Modern => "",
LauncherStyle::Classic => "flat"
},
#[watch]
remove_css_class: match model.style {
LauncherStyle::Modern => "flat",
LauncherStyle::Classic => ""
set_css_classes: match model.style {
LauncherStyle::Modern => &[""],
LauncherStyle::Classic => &["flat"]
},
pack_end = &gtk::MenuButton {
@ -330,10 +326,6 @@ impl SimpleComponent for App {
let widgets = view_output!();
if crate::APP_DEBUG {
widgets.main_window.add_css_class("devel");
}
let about_dialog_broker: MessageBroker<AboutDialog> = MessageBroker::new();
unsafe {