Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging improvements #57

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ panic = "abort"

[workspace.dependencies]
async-trait = "0.1.73"
tokio = { version = "1.28.2", features = ["rt", "macros", "process"] }
tokio = { version = "1.38.1", features = ["rt", "macros", "process"] }
tokio-stream = "0.1.15"
tokio-util = "0.7.11"

itertools = "0.13.0"
typed-builder = "0.18.2"
Expand Down
3 changes: 2 additions & 1 deletion crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pollster = "0.3.0"
tracing-appender = "0.2.2"
once_cell = "1.19.0"
parking_lot = { version = "0.12.3", features = ["serde"] }
time = { version = "0.3.36", features = ["local-offset"] }

[lints.rust]
rust_2018_idioms = "deny"
rust_2018_idioms = "deny"
21 changes: 11 additions & 10 deletions crates/client/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use crate::{
errors_pool::ErrorPoolExt,
states::States,
views::{self, profiles::ProfilesPage, settings::SettingsPage, ModManager, ProfileInfo, View},
subscriber::EguiLayer,
views::{self, profiles::ProfilesPage, settings::SettingsPage, Logs, ModManager, ProfileInfo, View},
Tab, TabKind,
};
use eframe::egui::{self, ScrollArea};
use eframe::egui::{self};
use egui_dock::TabViewer;
use egui_file_dialog::FileDialog;
use egui_task_manager::TaskManager;
use egui_tracing::EventCollector;
use nomi_core::{
repository::launcher_manifest::{Latest, LauncherManifest},
state::get_launcher_manifest,
};

pub struct MyContext {
pub collector: EventCollector,
pub egui_layer: EguiLayer,
pub launcher_manifest: &'static LauncherManifest,
pub file_dialog: FileDialog,

Expand All @@ -27,7 +27,7 @@ pub struct MyContext {
}

impl MyContext {
pub fn new(collector: EventCollector) -> Self {
pub fn new(egui_layer: EguiLayer) -> Self {
const EMPTY_MANIFEST: &LauncherManifest = &LauncherManifest {
latest: Latest {
release: String::new(),
Expand All @@ -39,7 +39,7 @@ impl MyContext {
let launcher_manifest_ref = pollster::block_on(get_launcher_manifest()).report_error().unwrap_or(EMPTY_MANIFEST);

Self {
collector,
egui_layer,
launcher_manifest: launcher_manifest_ref,
file_dialog: FileDialog::new(),
is_profile_window_open: false,
Expand Down Expand Up @@ -82,6 +82,7 @@ impl TabViewer for MyContext {
profiles_state: &mut self.states.profiles,
menu_state: &mut self.states.add_profile_menu_state,
tabs_state: &mut self.states.tabs,
logs_state: &self.states.logs_state,

launcher_manifest: self.launcher_manifest,
is_profile_window_open: &mut self.is_profile_window_open,
Expand All @@ -95,11 +96,11 @@ impl TabViewer for MyContext {
file_dialog: &mut self.file_dialog,
}
.ui(ui),
TabKind::Logs => {
ScrollArea::horizontal().show(ui, |ui| {
ui.add(egui_tracing::Logs::new(self.collector.clone()));
});
TabKind::Logs => Logs {
egui_layer: &self.egui_layer,
logs_state: &mut self.states.logs_state,
}
.ui(ui),
TabKind::DownloadProgress => {
views::DownloadingProgress {
manager: &self.manager,
Expand Down
18 changes: 11 additions & 7 deletions crates/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Remove console window
#![windows_subsystem = "windows"]

use collections::{AssetsCollection, GameDownloadingCollection, GameRunnerCollection, JavaCollection};
use context::MyContext;
use eframe::{
Expand All @@ -6,9 +9,9 @@ use eframe::{
};
use egui_dock::{DockArea, DockState, NodeIndex, Style};
use egui_notify::Toasts;
use egui_tracing::EventCollector;
use open_directory::open_directory_native;
use std::path::Path;
use subscriber::EguiLayer;
use ui_ext::TOASTS_ID;
use views::{add_tab_menu::AddTab, View};

Expand All @@ -33,6 +36,7 @@ pub mod open_directory;

pub mod collections;
pub mod progress;
pub mod subscriber;

pub mod tab;
pub use tab::*;
Expand All @@ -42,8 +46,6 @@ pub mod states;
pub use consts::*;

fn main() {
let collector = egui_tracing::EventCollector::default().with_level(Level::INFO);

let appender = tracing_appender::rolling::hourly(DOT_NOMI_LOGS_DIR, "nomi.log");
let (non_blocking, _guard) = tracing_appender::non_blocking(appender);

Expand All @@ -53,9 +55,11 @@ fn main() {
let stdout_sub = Layer::new().with_writer(std::io::stdout.with_max_level(Level::DEBUG)).pretty();
// stdout_sub.set_ansi(false);

let egui_layer = EguiLayer::new().with_level(Level::DEBUG);

let subscriber = tracing_subscriber::registry()
.with(EnvFilter::builder().parse("client=debug,nomi_core=debug").unwrap())
.with(collector.clone())
.with(egui_layer.clone())
.with(stdout_sub)
.with(file_sub);

Expand All @@ -73,7 +77,7 @@ fn main() {
native_options,
Box::new(|cc| {
egui_extras::install_image_loaders(&cc.egui_ctx);
Ok(Box::new(MyTabs::new(collector)))
Ok(Box::new(MyTabs::new(egui_layer)))
}),
);

Expand All @@ -86,7 +90,7 @@ struct MyTabs {
}

impl MyTabs {
pub fn new(collector: EventCollector) -> Self {
pub fn new(egui_layer: EguiLayer) -> Self {
let tabs = [TabKind::Profiles, TabKind::Logs, TabKind::Settings]
.map(|kind| Tab { id: kind.id(), kind })
.into();
Expand All @@ -104,7 +108,7 @@ impl MyTabs {
);

Self {
context: MyContext::new(collector),
context: MyContext::new(egui_layer),
dock_state,
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/client/src/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ use crate::{
add_tab_menu::TabsState,
profiles::ProfilesState,
settings::{ClientSettingsState, SettingsState},
AddProfileMenuState, ModManagerState, ProfileInfoState, ProfilesConfig,
AddProfileMenuState, LogsState, ModManagerState, ProfileInfoState, ProfilesConfig,
},
};

pub struct States {
pub tabs: TabsState,
pub errors_pool: ErrorsPoolState,

pub logs_state: LogsState,
pub java: JavaState,
pub profiles: ProfilesState,
pub settings: SettingsState,
Expand All @@ -42,8 +43,9 @@ impl Default for States {

Self {
tabs: TabsState::new(),
java: JavaState::new(),
errors_pool: ErrorsPoolState::default(),
logs_state: LogsState::new(),
java: JavaState::new(),
profiles: ProfilesState {
currently_downloading_profiles: HashSet::new(),
profiles: read_toml_config_sync::<ProfilesConfig>(DOT_NOMI_PROFILES_CONFIG).unwrap_or_default(),
Expand Down
Loading
Loading