Embracing tracing

This commit is contained in:
Jonathan Johnson 2023-11-08 16:16:08 -08:00
parent ad57e02e4f
commit 9596eaac17
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
5 changed files with 140 additions and 7 deletions

106
Cargo.lock generated
View file

@ -638,6 +638,8 @@ dependencies = [
"kempt",
"kludgine",
"pollster",
"tracing",
"tracing-subscriber",
]
[[package]]
@ -1148,6 +1150,16 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "num-integer"
version = "0.1.45"
@ -1265,6 +1277,12 @@ dependencies = [
"libredox",
]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "owned_ttf_parser"
version = "0.20.0"
@ -1309,6 +1327,12 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "pin-project-lite"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "pkg-config"
version = "0.3.27"
@ -1528,6 +1552,15 @@ dependencies = [
"syn",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "slotmap"
version = "1.0.6"
@ -1670,6 +1703,16 @@ dependencies = [
"syn",
]
[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tiny-skia"
version = "0.11.2"
@ -1727,6 +1770,63 @@ dependencies = [
"winnow",
]
[[package]]
name = "tracing"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
dependencies = [
"nu-ansi-term",
"sharded-slab",
"smallvec",
"thread_local",
"tracing-core",
"tracing-log",
]
[[package]]
name = "ttf-parser"
version = "0.19.2"
@ -1799,6 +1899,12 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vec_map"
version = "0.8.2"

View file

@ -3,7 +3,9 @@ name = "gooey"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["tracing-output"]
tracing-output = ["dep:tracing-subscriber"]
[dependencies]
kludgine = { git = "https://github.com/khonsulabs/kludgine", features = [
@ -13,6 +15,10 @@ alot = "0.3"
interner = "0.2.1"
kempt = "0.2.1"
intentional = "0.1.0"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3", optional = true }
# [patch."https://github.com/khonsulabs/kludgine"]
# kludgine = { path = "../kludgine2" }

View file

@ -211,7 +211,7 @@ impl<'context, 'window> EventContext<'context, 'window> {
}
if activation_changes == MAX_ITERS {
eprintln!(
tracing::error!(
"activation change force stopped after {activation_changes} sequential changes"
);
}
@ -261,7 +261,7 @@ impl<'context, 'window> EventContext<'context, 'window> {
}
if focus_changes == MAX_ITERS {
eprintln!("focus change force stopped after {focus_changes} sequential changes");
tracing::error!("focus change force stopped after {focus_changes} sequential changes");
}
}

View file

@ -136,3 +136,19 @@ macro_rules! styles {
$crate::styles!($($component => $value),*)
}};
}
fn initialize_tracing() {
#[cfg(feature = "tracing-output")]
{
use tracing::Level;
#[cfg(debug_assertions)]
const MAX_LEVEL: Level = Level::DEBUG;
#[cfg(not(debug_assertions))]
const MAX_LEVEL: Level = Level::ERROR;
let _result = tracing_subscriber::fmt::fmt()
.with_max_level(MAX_LEVEL)
.try_init();
}
}

View file

@ -20,6 +20,7 @@ use kludgine::figures::units::Px;
use kludgine::figures::{IntoSigned, Point, Rect, Size};
use kludgine::render::Drawing;
use kludgine::Kludgine;
use tracing::Level;
use crate::context::{
AsEventContext, EventContext, Exclusive, GraphicsContext, LayoutContext, RedrawStatus,
@ -34,7 +35,7 @@ use crate::widget::{
EventHandling, ManagedWidget, Widget, WidgetId, WidgetInstance, HANDLED, IGNORED,
};
use crate::window::sealed::WindowCommand;
use crate::{ConstraintLimit, Run};
use crate::{initialize_tracing, ConstraintLimit, Run};
/// A currently running Gooey window.
pub struct RunningWindow<'window> {
@ -191,6 +192,7 @@ where
Behavior: WindowBehavior,
{
fn run(self) -> crate::Result {
initialize_tracing();
GooeyWindow::<Behavior>::run_with(AssertUnwindSafe(sealed::Context {
user: self.context,
settings: RefCell::new(sealed::WindowSettings {
@ -517,9 +519,12 @@ where
);
}
_ => {
println!(
"Ignored Keyboard Input: {:?} ({:?}); {:?}",
input.logical_key, input.physical_key, input.state
tracing::event!(
Level::DEBUG,
logical = ?input.logical_key,
physical = ?input.physical_key,
state = ?input.state,
"Ignored Keyboard Input",
);
}
}