Changed debug logging

- stdout logs got rid of rustls messages and now are pretty styled
- logs are saved into the `debug.log` file in the launcher folder
  they're not filtered and contain all the messages
- toasts timeout fixed to 5 seconds
- added "save" button which will, well, not save logs
  but open `debug.log` file using `xdg-open`
This commit is contained in:
Observer KRypt0n_ 2023-02-11 12:34:39 +02:00
parent 4965a9f005
commit 44d074d864
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
4 changed files with 48 additions and 7 deletions

View file

@ -3,6 +3,7 @@ none = None
default = Default default = Default
details = Details details = Details
close = Close close = Close
save = Save
checking-free-space = Checking free space checking-free-space = Checking free space

View file

@ -3,6 +3,7 @@ none = Нет
default = По умолчанию default = По умолчанию
details = Подробнее details = Подробнее
close = Закрыть close = Закрыть
save = Сохранить
checking-free-space = Проверка свободного места checking-free-space = Проверка свободного места

View file

@ -4,6 +4,8 @@ use anime_launcher_sdk::config;
use anime_launcher_sdk::anime_game_core::prelude::*; use anime_launcher_sdk::anime_game_core::prelude::*;
use anime_launcher_sdk::anime_game_core::genshin::prelude::*; use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
use tracing_subscriber::prelude::*;
pub mod i18n; pub mod i18n;
pub mod ui; pub mod ui;
@ -25,6 +27,9 @@ pub fn is_ready() -> bool {
} }
lazy_static::lazy_static! { lazy_static::lazy_static! {
/// Path to `debug.log` file. Standard is `$HOME/.local/share/anime-game-launcher/debug.log`
pub static ref DEBUG_FILE: std::path::PathBuf = anime_launcher_sdk::consts::launcher_dir().unwrap_or_default().join("debug.log");
/// Config loaded on the app's start. Use `config::get()` to get up to date config instead. /// Config loaded on the app's start. Use `config::get()` to get up to date config instead.
/// This one is used to prepare some launcher UI components on start /// This one is used to prepare some launcher UI components on start
pub static ref CONFIG: config::Config = config::get().expect("Failed to load config"); pub static ref CONFIG: config::Config = config::get().expect("Failed to load config");
@ -56,12 +61,32 @@ lazy_static::lazy_static! {
} }
fn main() { fn main() {
tracing_subscriber::fmt() let stdout = tracing_subscriber::fmt::layer().pretty();
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::FULL)
.with_max_level(if APP_DEBUG || std::env::args().any(|arg| &arg == "--debug") { 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);
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 tracing::Level::TRACE
} else { } else {
tracing::Level::WARN tracing::Level::WARN
}
}))
.with_filter(tracing_subscriber::filter::filter_fn(|metadata| {
!metadata.target().starts_with("rustls")
}))
.and_then(debug_log)
}) })
.init(); .init();

View file

@ -222,7 +222,7 @@ impl SimpleAsyncComponent for App {
AppMsg::Toast { title, description } => unsafe { AppMsg::Toast { title, description } => unsafe {
let toast = adw::Toast::new(&title); let toast = adw::Toast::new(&title);
toast.set_timeout(5000); toast.set_timeout(5);
if let Some(description) = description { if let Some(description) = description {
toast.set_button_label(Some(&tr("details"))); toast.set_button_label(Some(&tr("details")));
@ -230,6 +230,20 @@ impl SimpleAsyncComponent for App {
let dialog = adw::MessageDialog::new(PREFERENCES_WINDOW.as_ref(), Some(&title), Some(&description)); let dialog = adw::MessageDialog::new(PREFERENCES_WINDOW.as_ref(), Some(&title), Some(&description));
dialog.add_response("close", &tr("close")); dialog.add_response("close", &tr("close"));
dialog.add_response("save", &tr("save"));
dialog.set_response_appearance("save", adw::ResponseAppearance::Suggested);
#[allow(unused_must_use)]
dialog.connect_response(Some("save"), |_, _| {
let result = std::process::Command::new("xdg-open")
.arg(crate::DEBUG_FILE.as_os_str())
.output();
if let Err(err) = result {
tracing::error!("Failed to open debug file: {}", err);
}
});
toast.connect_button_clicked(move |_| { toast.connect_button_clicked(move |_| {
dialog.show(); dialog.show();