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

Use tracing crate for logging #1192

Merged
merged 9 commits into from Feb 1, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
* Added `TextStyle::resolve`.
* `Context::load_texture` to convert an image into a texture which can be displayed using e.g. `ui.image(texture, size)` ([#1110](https://github.com/emilk/egui/pull/1110)).
* Added `Ui::add_visible` and `Ui::add_visible_ui`.
* Opt-in dependency on `tracing` crate for logging warnings ([#1192](https://github.com/emilk/egui/pull/1192)).
* Added `CollapsingHeader::icon` to override the default open/close icon using a custom function. ([1147](https://github.com/emilk/egui/pull/1147)).
* Added `Plot::x_axis_formatter` and `Plot::y_axis_formatter` for custom axis labels ([#1130](https://github.com/emilk/egui/pull/1130)).
* Added `ui.data()`, `ctx.data()`, `ctx.options()` and `ctx.tessellation_options()` ([#1175](https://github.com/emilk/egui/pull/1175)).
Expand Down
99 changes: 99 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions docs/index.html
Expand Up @@ -122,17 +122,18 @@
// We'll defer our execution until the wasm is ready to go.
// Here we tell bindgen the path to the wasm file so it can start
// initialization and return to us a promise when it's done.
console.debug("loading wasm…");
wasm_bindgen("./egui_demo_app_bg.wasm")
.then(on_wasm_loaded)
.catch(on_wasm_error);

function on_wasm_loaded() {
console.log("loaded wasm, starting egui app…");
console.debug("wasm loaded. starting egui app…");

// This call installs a bunch of callbacks and then returns:
wasm_bindgen.start("the_canvas_id");

console.log("egui app started.");
console.debug("egui app started.");
document.getElementById("center_text").remove();
}

Expand Down
1 change: 1 addition & 0 deletions eframe/CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ NOTE: [`egui_web`](../egui_web/CHANGELOG.md), [`egui-winit`](../egui-winit/CHANG
* Fix horizontal scrolling direction on Linux.
* Added `App::on_exit_event` ([#1038](https://github.com/emilk/egui/pull/1038))
* Shift-scroll will now result in horizontal scrolling on all platforms ([#1136](https://github.com/emilk/egui/pull/1136)).
* Log using the `tracing` crate. Log to stdout by adding `tracing_subscriber::fmt::init();` to your `main` ([#1192](https://github.com/emilk/egui/pull/1192)).


## 0.16.0 - 2021-12-29
Expand Down
3 changes: 2 additions & 1 deletion egui-winit/Cargo.toml
Expand Up @@ -22,8 +22,9 @@ include = [
all-features = true

[dependencies]
egui = { version = "0.16.0", path = "../egui", default-features = false, features = ["single_threaded"] }
egui = { version = "0.16.0", path = "../egui", default-features = false, features = ["single_threaded", "tracing"] }
instant = { version = "0.1", features = ["wasm-bindgen"] }
tracing = "0.1"
winit = "0.26.1"

epi = { version = "0.16.0", path = "../epi", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions egui-winit/src/clipboard.rs
Expand Up @@ -29,7 +29,7 @@ impl Clipboard {
match clipboard.get_contents() {
Ok(contents) => Some(contents),
Err(err) => {
eprintln!("Paste error: {}", err);
tracing::error!("Paste error: {}", err);
None
}
}
Expand All @@ -46,7 +46,7 @@ impl Clipboard {
if let Some(clipboard) = &mut self.copypasta {
use copypasta::ClipboardProvider as _;
if let Err(err) = clipboard.set_contents(text) {
eprintln!("Copy/Cut error: {}", err);
tracing::error!("Copy/Cut error: {}", err);
}
}

Expand All @@ -62,7 +62,7 @@ fn init_copypasta() -> Option<copypasta::ClipboardContext> {
match copypasta::ClipboardContext::new() {
Ok(clipboard) => Some(clipboard),
Err(err) => {
eprintln!("Failed to initialize clipboard: {}", err);
tracing::error!("Failed to initialize clipboard: {}", err);
None
}
}
Expand Down
4 changes: 2 additions & 2 deletions egui-winit/src/lib.rs
Expand Up @@ -577,12 +577,12 @@ impl State {
fn open_url_in_browser(_url: &str) {
#[cfg(feature = "webbrowser")]
if let Err(err) = webbrowser::open(_url) {
eprintln!("Failed to open url: {}", err);
tracing::warn!("Failed to open url: {}", err);
}

#[cfg(not(feature = "webbrowser"))]
{
eprintln!("Cannot open url - feature \"links\" not enabled.");
tracing::warn!("Cannot open url - feature \"links\" not enabled.");
}
}

Expand Down
8 changes: 4 additions & 4 deletions egui-winit/src/screen_reader.rs
Expand Up @@ -15,11 +15,11 @@ impl Default for ScreenReader {
fn default() -> Self {
let tts = match tts::Tts::default() {
Ok(screen_reader) => {
eprintln!("Initialized screen reader.");
tracing::debug!("Initialized screen reader.");
Some(screen_reader)
}
Err(err) => {
eprintln!("Failed to load screen reader: {}", err);
tracing::warn!("Failed to load screen reader: {}", err);
None
}
};
Expand All @@ -38,10 +38,10 @@ impl ScreenReader {
return;
}
if let Some(tts) = &mut self.tts {
eprintln!("Speaking: {:?}", text);
tracing::debug!("Speaking: {:?}", text);
let interrupt = true;
if let Err(err) = tts.speak(text, interrupt) {
eprintln!("Failed to read: {}", err);
tracing::warn!("Failed to read: {}", err);
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions egui/Cargo.toml
Expand Up @@ -28,15 +28,22 @@ epaint = { version = "0.16.0", path = "../epaint", default-features = false }

ahash = "0.7"
nohash-hasher = "0.2"

# Optional:
ron = { version = "0.7", optional = true }
serde = { version = "1", features = ["derive", "rc"], optional = true }
# egui doesn't log much, but when it does, it uses `tracing`
tracing = { version = "0.1", optional = true }

[features]
default = ["default_fonts", "single_threaded"]

# add compatibility with https://crates.io/crates/cint
cint = ["epaint/cint"]

# implement bytemuck on most types.
convert_bytemuck = ["epaint/convert_bytemuck"]

# If set, egui will use `include_bytes!` to bundle some fonts.
# If you plan on specifying your own fonts you may disable this feature.
default_fonts = ["epaint/default_fonts"]
Expand All @@ -55,9 +62,6 @@ persistence = ["serde", "epaint/serialize", "ron"]
# implement serde on most types.
serialize = ["serde", "epaint/serialize"]

# implement bytemuck on most types.
convert_bytemuck = ["epaint/convert_bytemuck"]

# multi_threaded is only needed if you plan to use the same egui::Context
# from multiple threads. It comes with a minor performance impact.
single_threaded = ["epaint/single_threaded"]
Expand Down
7 changes: 4 additions & 3 deletions egui/src/util/id_type_map.rs
Expand Up @@ -275,11 +275,12 @@ impl Element {
fn from_ron_str<T: serde::de::DeserializeOwned>(ron: &str) -> Option<T> {
match ron::from_str::<T>(ron) {
Ok(value) => Some(value),
Err(err) => {
eprintln!(
Err(_err) => {
#[cfg(feature = "tracing")]
tracing::warn!(
"egui: Failed to deserialize {} from memory: {}, ron error: {:?}",
std::any::type_name::<T>(),
err,
_err,
ron
);
None
Expand Down
1 change: 1 addition & 0 deletions egui_demo_app/Cargo.toml
Expand Up @@ -17,6 +17,7 @@ eframe = { version = "0.16.0", path = "../eframe" }
# eframe = { version = "0.16.0", path = "../eframe", default-features = false, features = ["default_fonts", "egui_glium"] }

egui_demo_lib = { version = "0.16.0", path = "../egui_demo_lib", features = ["extra_debug_asserts"] }
tracing-subscriber = "0.3"

[features]
default = ["persistence"]
Expand Down
3 changes: 3 additions & 0 deletions egui_demo_app/src/main.rs
Expand Up @@ -7,6 +7,9 @@

// When compiling natively:
fn main() {
// Log to stdout (if you run with `RUST_LOG=debug`).
tracing_subscriber::fmt::init();

let app = egui_demo_lib::WrapApp::default();
let options = eframe::NativeOptions {
// Let's show off that we support transparent windows
Expand Down
1 change: 1 addition & 0 deletions egui_glow/Cargo.toml
Expand Up @@ -32,6 +32,7 @@ epi = { version = "0.16.0", path = "../epi", optional = true }
bytemuck = "1.7"
glow = "0.11"
memoffset = "0.6"
tracing = "0.1"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui-winit = { version = "0.16.0", path = "../egui-winit", default-features = false, features = ["epi"], optional = true }
Expand Down
3 changes: 1 addition & 2 deletions egui_glow/src/epi_backend.rs
Expand Up @@ -60,8 +60,7 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
)));

let mut painter = crate::Painter::new(&gl, None, "")
.map_err(|error| eprintln!("some OpenGL error occurred {}\n", error))
.unwrap();
.unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error));
let mut integration = egui_winit::epi::EpiIntegration::new(
"egui_glow",
painter.max_texture_side(),
Expand Down
5 changes: 1 addition & 4 deletions egui_glow/src/lib.rs
Expand Up @@ -124,10 +124,7 @@ impl EguiGlow {
pub fn new(window: &winit::window::Window, gl: &glow::Context) -> Self {
let painter = crate::Painter::new(gl, None, "")
.map_err(|error| {
crate::misc_util::glow_print_error(format!(
"error occurred in initializing painter:\n{}",
error
));
tracing::error!("error occurred in initializing painter:\n{}", error);
})
.unwrap();

Expand Down