From 94206a24ec826e085a8a2faff3914d4e341e0179 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sat, 10 Feb 2024 09:36:26 +1100 Subject: [PATCH] logging --- Cargo.lock | 35 +++++++++++++++++++++++++++++++- cli/Cargo.toml | 1 + cli/src/main.rs | 2 +- frontend-common/Cargo.toml | 2 ++ frontend-common/src/audio.rs | 6 +++--- frontend-common/src/lib.rs | 1 + lib/Cargo.toml | 1 + lib/src/config/mod.rs | 4 ++-- lib/src/processor/memory.rs | 4 ++-- lib/src/renderer/vulkan/debug.rs | 2 +- lib/src/util.rs | 4 ++-- 11 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d32008..4a865a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -681,6 +681,7 @@ dependencies = [ "ctrlc", "frontend-common", "gb-emu-lib", + "log", ] [[package]] @@ -1267,6 +1268,29 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05e7cf40684ae96ade6232ed84582f40ce0a66efcd43a5117aef610534f8e0b8" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1422,10 +1446,12 @@ dependencies = [ "bytemuck", "chrono", "cpal", + "env_logger", "futures", "gb-emu-lib", "gilrs", "image", + "log", "nokhwa", "raw-window-handle 0.6.0", "send_wrapper", @@ -1539,6 +1565,7 @@ dependencies = [ "librashader", "librashader-common", "librashader-presets", + "log", "naga", "num-traits", "pixels", @@ -1615,7 +1642,7 @@ dependencies = [ "vec_map", "wasm-bindgen", "web-sys", - "windows 0.44.0", + "windows 0.52.0", ] [[package]] @@ -1851,6 +1878,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "iana-time-zone" version = "0.1.59" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 9e06fb5..369ff90 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -12,3 +12,4 @@ frontend-common = { workspace = true } gb-emu-lib = { workspace = true } clap = { version = "4.4", features = ["derive"] } ctrlc = "3.4" +log = "0.4.20" diff --git a/cli/src/main.rs b/cli/src/main.rs index 7b73e2e..0815844 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -153,7 +153,7 @@ fn main() { } { println!("{string}"); } else { - println!("Error getting config string"); + log::error!("Error getting config string"); } } } diff --git a/frontend-common/Cargo.toml b/frontend-common/Cargo.toml index 4e991c9..2e25e9c 100644 --- a/frontend-common/Cargo.toml +++ b/frontend-common/Cargo.toml @@ -31,3 +31,5 @@ serde = { version = "1.0", features = ["derive"] } image = { version = "0.24", default-features = false, features = ["png"] } bytemuck = "1.14" chrono = "0.4" +log = "0.4.20" +env_logger = "0.11.1" diff --git a/frontend-common/src/audio.rs b/frontend-common/src/audio.rs index 50b15da..10ab89c 100644 --- a/frontend-common/src/audio.rs +++ b/frontend-common/src/audio.rs @@ -37,7 +37,7 @@ pub fn create_output(muted: bool) -> (AudioOutput, Stream) { cpal::BufferSize::Fixed(default_buffer_size.min(*max).max(*min)); } - println!("Using buffer size {:?}", stream_config.buffer_size); + log::info!("Using buffer size {:?}", stream_config.buffer_size); let (output, mut rx) = AudioOutput::new(sample_rate as f32, buffers_per_frame, DOWNSAMPLE_TYPE); @@ -54,7 +54,7 @@ pub fn create_output(muted: bool) -> (AudioOutput, Stream) { } }, move |err| { - eprintln!("audio error: {err}"); + log::error!("audio error: {err}"); }, None, ) @@ -71,7 +71,7 @@ pub fn create_output(muted: bool) -> (AudioOutput, Stream) { } }, move |err| { - eprintln!("audio error: {err}"); + log::error!("audio error: {err}"); }, None, ) diff --git a/frontend-common/src/lib.rs b/frontend-common/src/lib.rs index d967077..0de5b81 100644 --- a/frontend-common/src/lib.rs +++ b/frontend-common/src/lib.rs @@ -111,6 +111,7 @@ pub fn prepare( options: RunOptions, receiver: Receiver>, ) -> PreparedEmulator { + env_logger::init(); let config = CONFIG_MANAGER.load_or_create_base_config(); let standalone_config: StandaloneConfig = CONFIG_MANAGER.load_or_create_config(); diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 9f1a364..cebabf0 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -53,6 +53,7 @@ ron = { version = "0.8", optional = true } lazy_static = "1.4" wgpu = { version = "0.19", optional = true } thiserror = { workspace = true } +log = "0.4.20" [build-dependencies] naga = { version = "0.19", optional = true, features = ["wgsl-in", "spv-out"] } diff --git a/lib/src/config/mod.rs b/lib/src/config/mod.rs index 07e970f..4bb7039 100644 --- a/lib/src/config/mod.rs +++ b/lib/src/config/mod.rs @@ -53,14 +53,14 @@ impl ConfigManager { None => { let config = C::default(); if let Ok(true) = self.path.join(C::name()).try_exists() { - eprintln!( + log::error!( "Failed to load \"{}\" config, but it exists on disk", C::name() ); } else { let result = self.save_custom_config(config.clone()); if let Err(e) = result { - eprintln!("Failed to save \"{}\" config: {e:#?}", C::name()); + log::error!("Failed to save \"{}\" config: {e:#?}", C::name()); } } config diff --git a/lib/src/processor/memory.rs b/lib/src/processor/memory.rs index b58bb36..e9a7a58 100644 --- a/lib/src/processor/memory.rs +++ b/lib/src/processor/memory.rs @@ -326,7 +326,7 @@ where CgbIoAddress::Pcm12 => self.apu.get_pcm_1_2(), CgbIoAddress::Pcm34 => self.apu.get_pcm_3_4(), CgbIoAddress::Unused(v) => { - eprintln!("attempt to get 0x{v:0>4X}"); + log::warn!("attempt to get unused address 0x{v:0>4X}"); 0xFF } } @@ -389,7 +389,7 @@ where CgbIoAddress::Pcm12 => {} CgbIoAddress::Pcm34 => {} CgbIoAddress::Unused(v) => { - eprintln!("attempt to set 0x{v:0>4X} to 0x{data:0>2X}") + log::error!("attempt to set unused address 0x{v:0>4X} to 0x{data:0>2X}") } } } diff --git a/lib/src/renderer/vulkan/debug.rs b/lib/src/renderer/vulkan/debug.rs index 60a6e46..34c900e 100644 --- a/lib/src/renderer/vulkan/debug.rs +++ b/lib/src/renderer/vulkan/debug.rs @@ -63,7 +63,7 @@ unsafe extern "system" fn vulkan_debug_callback( std::ffi::CStr::from_ptr(callback_data.p_message).to_string_lossy() }; - println!( + log::warn!( "{message_severity:?}:\n{message_type:?} [{message_id_name} ({message_id_number})] : {message}\n", ); diff --git a/lib/src/util.rs b/lib/src/util.rs index ab4dae0..b381d91 100644 --- a/lib/src/util.rs +++ b/lib/src/util.rs @@ -20,7 +20,7 @@ where match self { Ok(val) => Some(val), Err(e) => { - eprintln!("{e:?}"); + log::error!("{e:?}"); None } } @@ -30,7 +30,7 @@ where match self { Ok(val) => Some(val), Err(e) => { - eprintln!("{context}: {e:?}"); + log::error!("{context}: {e:?}"); None } }