Use `log` crate instead of `eprintln` & remove some unwraps (#5010)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> - I fixed the TODO to use the `log` crate instead of `eprintln` - Set the rust-version in the `scripts/check.sh` to the same as egui is on - I made xtask use anyhow to remove some unwraps * [x] I have followed the instructions in the PR template
This commit is contained in:
parent
66076101e1
commit
1488ffa35a
|
|
@ -3155,6 +3155,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eframe",
|
"eframe",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
"log",
|
||||||
"puffin",
|
"puffin",
|
||||||
"puffin_http",
|
"puffin_http",
|
||||||
]
|
]
|
||||||
|
|
@ -3583,6 +3584,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eframe",
|
"eframe",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,7 @@ negative_feature_names = "warn"
|
||||||
nonstandard_macro_braces = "warn"
|
nonstandard_macro_braces = "warn"
|
||||||
option_option = "warn"
|
option_option = "warn"
|
||||||
path_buf_push_overwrite = "warn"
|
path_buf_push_overwrite = "warn"
|
||||||
|
print_stderr = "warn"
|
||||||
ptr_as_ptr = "warn"
|
ptr_as_ptr = "warn"
|
||||||
ptr_cast_constness = "warn"
|
ptr_cast_constness = "warn"
|
||||||
pub_without_shorthand = "warn"
|
pub_without_shorthand = "warn"
|
||||||
|
|
@ -251,11 +252,11 @@ wildcard_dependencies = "warn"
|
||||||
wildcard_imports = "warn"
|
wildcard_imports = "warn"
|
||||||
zero_sized_map_values = "warn"
|
zero_sized_map_values = "warn"
|
||||||
|
|
||||||
|
|
||||||
# TODO(emilk): enable more of these lints:
|
# TODO(emilk): enable more of these lints:
|
||||||
iter_over_hash_type = "allow"
|
iter_over_hash_type = "allow"
|
||||||
let_underscore_untyped = "allow"
|
let_underscore_untyped = "allow"
|
||||||
missing_assert_message = "allow"
|
missing_assert_message = "allow"
|
||||||
print_stderr = "allow" # TODO(emilk): use `log` crate instead
|
|
||||||
should_panic_without_expect = "allow"
|
should_panic_without_expect = "allow"
|
||||||
too_many_lines = "allow"
|
too_many_lines = "allow"
|
||||||
unwrap_used = "allow" # TODO(emilk): We really wanna warn on this one
|
unwrap_used = "allow" # TODO(emilk): We really wanna warn on this one
|
||||||
|
|
|
||||||
|
|
@ -1547,7 +1547,7 @@ fn save_screenshot_and_exit(
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| {
|
||||||
panic!("Failed to save screenshot to {path:?}: {err}");
|
panic!("Failed to save screenshot to {path:?}: {err}");
|
||||||
});
|
});
|
||||||
eprintln!("Screenshot saved to {path:?}.");
|
log::info!("Screenshot saved to {path:?}.");
|
||||||
|
|
||||||
#[allow(clippy::exit)]
|
#[allow(clippy::exit)]
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
|
|
||||||
|
|
@ -417,7 +417,7 @@ mod tests {
|
||||||
];
|
];
|
||||||
|
|
||||||
for (i, w) in widgets.iter().enumerate() {
|
for (i, w) in widgets.iter().enumerate() {
|
||||||
eprintln!("Widget {i}: {:?}", w.id);
|
println!("Widget {i}: {:?}", w.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In the middle of the bg-left-label:
|
// In the middle of the bg-left-label:
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ fn start_puffin_server() {
|
||||||
|
|
||||||
match puffin_http::Server::new("127.0.0.1:8585") {
|
match puffin_http::Server::new("127.0.0.1:8585") {
|
||||||
Ok(puffin_server) => {
|
Ok(puffin_server) => {
|
||||||
eprintln!("Run: cargo install puffin_viewer && puffin_viewer --url 127.0.0.1:8585");
|
log::info!("Run: cargo install puffin_viewer && puffin_viewer --url 127.0.0.1:8585");
|
||||||
|
|
||||||
std::process::Command::new("puffin_viewer")
|
std::process::Command::new("puffin_viewer")
|
||||||
.arg("--url")
|
.arg("--url")
|
||||||
|
|
@ -78,7 +78,7 @@ fn start_puffin_server() {
|
||||||
std::mem::forget(puffin_server);
|
std::mem::forget(puffin_server);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Failed to start puffin server: {err}");
|
log::error!("Failed to start puffin server: {err}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -775,22 +775,22 @@ mod tests {
|
||||||
fn test_ray_intersection() {
|
fn test_ray_intersection() {
|
||||||
let rect = Rect::from_min_max(pos2(1.0, 1.0), pos2(3.0, 3.0));
|
let rect = Rect::from_min_max(pos2(1.0, 1.0), pos2(3.0, 3.0));
|
||||||
|
|
||||||
eprintln!("Righward ray from left:");
|
println!("Righward ray from left:");
|
||||||
assert!(rect.intersects_ray(pos2(0.0, 2.0), Vec2::RIGHT));
|
assert!(rect.intersects_ray(pos2(0.0, 2.0), Vec2::RIGHT));
|
||||||
|
|
||||||
eprintln!("Righward ray from center:");
|
println!("Righward ray from center:");
|
||||||
assert!(rect.intersects_ray(pos2(2.0, 2.0), Vec2::RIGHT));
|
assert!(rect.intersects_ray(pos2(2.0, 2.0), Vec2::RIGHT));
|
||||||
|
|
||||||
eprintln!("Righward ray from right:");
|
println!("Righward ray from right:");
|
||||||
assert!(!rect.intersects_ray(pos2(4.0, 2.0), Vec2::RIGHT));
|
assert!(!rect.intersects_ray(pos2(4.0, 2.0), Vec2::RIGHT));
|
||||||
|
|
||||||
eprintln!("Leftward ray from left:");
|
println!("Leftward ray from left:");
|
||||||
assert!(!rect.intersects_ray(pos2(0.0, 2.0), Vec2::LEFT));
|
assert!(!rect.intersects_ray(pos2(0.0, 2.0), Vec2::LEFT));
|
||||||
|
|
||||||
eprintln!("Leftward ray from center:");
|
println!("Leftward ray from center:");
|
||||||
assert!(rect.intersects_ray(pos2(2.0, 2.0), Vec2::LEFT));
|
assert!(rect.intersects_ray(pos2(2.0, 2.0), Vec2::LEFT));
|
||||||
|
|
||||||
eprintln!("Leftward ray from right:");
|
println!("Leftward ray from right:");
|
||||||
assert!(rect.intersects_ray(pos2(4.0, 2.0), Vec2::LEFT));
|
assert!(rect.intersects_ray(pos2(4.0, 2.0), Vec2::LEFT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,6 @@ pub fn best_in_range_f64(min: f64, max: f64) -> f64 {
|
||||||
let min_str = to_decimal_string(min / exp_factor);
|
let min_str = to_decimal_string(min / exp_factor);
|
||||||
let max_str = to_decimal_string(max / exp_factor);
|
let max_str = to_decimal_string(max / exp_factor);
|
||||||
|
|
||||||
// eprintln!("min_str: {:?}", min_str);
|
|
||||||
// eprintln!("max_str: {:?}", max_str);
|
|
||||||
|
|
||||||
let mut ret_str = [0; NUM_DECIMALS];
|
let mut ret_str = [0; NUM_DECIMALS];
|
||||||
|
|
||||||
// Select the common prefix:
|
// Select the common prefix:
|
||||||
|
|
|
||||||
|
|
@ -1749,8 +1749,12 @@ impl Tessellator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if galley.pixels_per_point != self.pixels_per_point {
|
if galley.pixels_per_point != self.pixels_per_point {
|
||||||
eprintln!("epaint: WARNING: pixels_per_point (dpi scale) have changed between text layout and tessellation. \
|
let warn = "epaint: WARNING: pixels_per_point (dpi scale) have changed between text layout and tessellation. \
|
||||||
You must recreate your text shapes if pixels_per_point changes.");
|
You must recreate your text shapes if pixels_per_point changes.";
|
||||||
|
#[cfg(feature = "log")]
|
||||||
|
log::warn!("{warn}");
|
||||||
|
#[cfg(not(feature = "log"))]
|
||||||
|
println!("{warn}");
|
||||||
}
|
}
|
||||||
|
|
||||||
out.vertices.reserve(galley.num_vertices);
|
out.vertices.reserve(galley.num_vertices);
|
||||||
|
|
|
||||||
|
|
@ -25,5 +25,6 @@ env_logger = { version = "0.10", default-features = false, features = [
|
||||||
"auto-color",
|
"auto-color",
|
||||||
"humantime",
|
"humantime",
|
||||||
] }
|
] }
|
||||||
|
log = { workspace = true }
|
||||||
puffin = "0.19"
|
puffin = "0.19"
|
||||||
puffin_http = "0.16"
|
puffin_http = "0.16"
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ use std::sync::{
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
|
||||||
fn main() -> eframe::Result {
|
fn main() -> eframe::Result {
|
||||||
|
let rust_log = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_owned());
|
||||||
|
std::env::set_var("RUST_LOG", rust_log);
|
||||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||||
start_puffin_server(); // NOTE: you may only want to call this if the users specifies some flag or clicks a button!
|
start_puffin_server(); // NOTE: you may only want to call this if the users specifies some flag or clicks a button!
|
||||||
|
|
||||||
|
|
@ -153,7 +155,7 @@ fn start_puffin_server() {
|
||||||
|
|
||||||
match puffin_http::Server::new("127.0.0.1:8585") {
|
match puffin_http::Server::new("127.0.0.1:8585") {
|
||||||
Ok(puffin_server) => {
|
Ok(puffin_server) => {
|
||||||
eprintln!("Run: cargo install puffin_viewer && puffin_viewer --url 127.0.0.1:8585");
|
log::info!("Run: cargo install puffin_viewer && puffin_viewer --url 127.0.0.1:8585");
|
||||||
|
|
||||||
std::process::Command::new("puffin_viewer")
|
std::process::Command::new("puffin_viewer")
|
||||||
.arg("--url")
|
.arg("--url")
|
||||||
|
|
@ -167,7 +169,7 @@ fn start_puffin_server() {
|
||||||
std::mem::forget(puffin_server);
|
std::mem::forget(puffin_server);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Failed to start puffin server: {err}");
|
log::error!("Failed to start puffin server: {err}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,4 @@ env_logger = { version = "0.10", default-features = false, features = [
|
||||||
"auto-color",
|
"auto-color",
|
||||||
"humantime",
|
"humantime",
|
||||||
] }
|
] }
|
||||||
|
log = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ fn main() -> eframe::Result {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
eprintln!("Starting first window…");
|
log::info!("Starting first window…");
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"First Window",
|
"First Window",
|
||||||
options.clone(),
|
options.clone(),
|
||||||
|
|
@ -21,7 +21,7 @@ fn main() -> eframe::Result {
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||||
|
|
||||||
eprintln!("Starting second window…");
|
log::info!("Starting second window…");
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"Second Window",
|
"Second Window",
|
||||||
options.clone(),
|
options.clone(),
|
||||||
|
|
@ -30,7 +30,7 @@ fn main() -> eframe::Result {
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||||
|
|
||||||
eprintln!("Starting third window…");
|
log::info!("Starting third window…");
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"Third Window",
|
"Third Window",
|
||||||
options,
|
options,
|
||||||
|
|
@ -53,7 +53,7 @@ impl eframe::App for MyApp {
|
||||||
ui.label(label_text);
|
ui.label(label_text);
|
||||||
|
|
||||||
if ui.button("Close").clicked() {
|
if ui.button("Close").clicked() {
|
||||||
eprintln!("Pressed Close button");
|
log::info!("Pressed Close button");
|
||||||
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ pub fn ask_to_run(mut cmd: Command, ask: bool, reason: &str) -> Result<(), DynEr
|
||||||
a => return Err(format!("Invalid answer `{a}`").into()),
|
a => return Err(format!("Invalid answer `{a}`").into()),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Running `{cmd:?}` to {reason}.");
|
println!("Running `{cmd:?}` to {reason}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = cmd.status()?;
|
let status = cmd.status()?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue