Skip to content

Commit

Permalink
Replace tracing with log (emilk#2928)
Browse files Browse the repository at this point in the history
* Replace tracing crate with log

It's just so much simpler to use

* Add `bacon wasm` job

* eframe: add a WebLogger for piping log events to the web console
  • Loading branch information
emilk authored Apr 18, 2023
1 parent 0f9e1a3 commit 9c9a54c
Show file tree
Hide file tree
Showing 48 changed files with 477 additions and 291 deletions.
291 changes: 174 additions & 117 deletions Cargo.lock

Large diffs are not rendered by default.

38 changes: 33 additions & 5 deletions bacon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,50 @@ default_job = "cranky"
[jobs]

[jobs.cranky]
command = ["cargo", "cranky", "--all-targets", "--all-features", "--color", "always"]
command = [
"cargo",
"cranky",
"--all-targets",
"--all-features",
"--color=always",
]
need_stdout = false
watch = ["tests", "benches", "examples"]

[jobs.wasm]
command = [
"cargo",
"cranky",
"-p=egui_demo_app",
"--lib",
"--target=wasm32-unknown-unknown",
"--target-dir=target_wasm",
"--all-features",
"--color=always",
]
need_stdout = false
watch = ["tests", "benches", "examples"]

[jobs.test]
command = ["cargo", "test", "--color", "always"]
command = ["cargo", "test", "--color=always"]
need_stdout = true
watch = ["tests"]

[jobs.doc]
command = ["cargo", "doc", "--color", "always", "--all-features", "--no-deps"]
command = ["cargo", "doc", "--color=always", "--all-features", "--no-deps"]
need_stdout = false

# if the doc compiles, then it opens in your browser and bacon switches
# to the previous job
[jobs.doc-open]
command = ["cargo", "doc", "--color", "always", "--all-features", "--no-deps", "--open"]
command = [
"cargo",
"doc",
"--color=always",
"--all-features",
"--no-deps",
"--open",
]
need_stdout = false
on_success = "back" # so that we don't open the browser at each change

Expand All @@ -31,7 +58,7 @@ on_success = "back" # so that we don't open the browser at each change
# way. Don't forget the `--color always` part or the errors won't be
# properly parsed.
[jobs.run]
command = ["cargo", "run", "--color", "always"]
command = ["cargo", "run", "--color=always"]
need_stdout = true

# You may define here keybindings that would be specific to
Expand All @@ -41,6 +68,7 @@ need_stdout = true
[keybindings]
i = "job:initial"
c = "job:cranky"
w = "job:wasm"
d = "job:doc-open"
t = "job:test"
r = "job:run"
8 changes: 4 additions & 4 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ wgpu = ["dep:wgpu", "dep:egui-wgpu", "dep:pollster"]
# - It's also important that we don't impose an android-activity backend by taking this choice away from applications.

## Enable the `native-activity` backend via `egui-winit` on Android
android-native-activity = [ "egui-winit/android-native-activity" ]
android-native-activity = ["egui-winit/android-native-activity"]
## Enable the `game-activity` backend via `egui-winit` on Android
android-game-activity = [ "egui-winit/android-game-activity" ]
android-game-activity = ["egui-winit/android-game-activity"]

[dependencies]
egui = { version = "0.21.0", path = "../egui", default-features = false, features = [
"bytemuck",
"tracing",
"log",
] }
log = { version = "0.4", features = ["std"] }
thiserror = "1.0.37"
tracing = { version = "0.1", default-features = false, features = ["std"] }

#! ### Optional dependencies
## Enable this when generating docs.
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ impl Frame {
#[doc(alias = "exit")]
#[doc(alias = "quit")]
pub fn close(&mut self) {
tracing::debug!("eframe::Frame::close called");
log::debug!("eframe::Frame::close called");
self.output.close = true;
}

Expand Down Expand Up @@ -1088,7 +1088,7 @@ pub fn get_value<T: serde::de::DeserializeOwned>(storage: &dyn Storage, key: &st
pub fn set_value<T: serde::Serialize>(storage: &mut dyn Storage, key: &str, value: &T) {
match ron::ser::to_string(value) {
Ok(string) => storage.set_string(key, string),
Err(err) => tracing::error!("eframe failed to encode data using ron: {}", err),
Err(err) => log::error!("eframe failed to encode data using ron: {}", err),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ pub fn run_native(
match renderer {
#[cfg(feature = "glow")]
Renderer::Glow => {
tracing::debug!("Using the glow renderer");
log::debug!("Using the glow renderer");
native::run::run_glow(app_name, native_options, app_creator)
}

#[cfg(feature = "wgpu")]
Renderer::Wgpu => {
tracing::debug!("Using the wgpu renderer");
log::debug!("Using the wgpu renderer");
native::run::run_wgpu(app_name, native_options, app_creator)
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ impl EpiIntegration {

match event {
WindowEvent::CloseRequested => {
tracing::debug!("Received WindowEvent::CloseRequested");
log::debug!("Received WindowEvent::CloseRequested");
self.close = app.on_close_event();
tracing::debug!("App::on_close_event returned {}", self.close);
log::debug!("App::on_close_event returned {}", self.close);
}
WindowEvent::Destroyed => {
tracing::debug!("Received WindowEvent::Destroyed");
log::debug!("Received WindowEvent::Destroyed");
self.close = true;
}
WindowEvent::MouseInput {
Expand Down Expand Up @@ -483,7 +483,7 @@ impl EpiIntegration {
self.can_drag_window = false;
if app_output.close {
self.close = app.on_close_event();
tracing::debug!("App::on_close_event returned {}", self.close);
log::debug!("App::on_close_event returned {}", self.close);
}
self.frame.output.visible = app_output.visible; // this is handled by post_present
self.frame.output.screenshot_requested = app_output.screenshot_requested;
Expand Down
10 changes: 5 additions & 5 deletions crates/eframe/src/native/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl FileStorage {
/// Store the state in this .ron file.
pub fn from_ron_filepath(ron_filepath: impl Into<PathBuf>) -> Self {
let ron_filepath: PathBuf = ron_filepath.into();
tracing::debug!("Loading app state from {:?}…", ron_filepath);
log::debug!("Loading app state from {:?}…", ron_filepath);
Self {
kv: read_ron(&ron_filepath).unwrap_or_default(),
ron_filepath,
Expand All @@ -40,7 +40,7 @@ impl FileStorage {
if let Some(proj_dirs) = directories_next::ProjectDirs::from("", "", app_name) {
let data_dir = proj_dirs.data_dir().to_path_buf();
if let Err(err) = std::fs::create_dir_all(&data_dir) {
tracing::warn!(
log::warn!(
"Saving disabled: Failed to create app path at {:?}: {}",
data_dir,
err
Expand All @@ -50,7 +50,7 @@ impl FileStorage {
Some(Self::from_ron_filepath(data_dir.join("app.ron")))
}
} else {
tracing::warn!("Saving disabled: Failed to find path to data_dir.");
log::warn!("Saving disabled: Failed to find path to data_dir.");
None
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ impl crate::Storage for FileStorage {
let file = std::fs::File::create(&file_path).unwrap();
let config = Default::default();
ron::ser::to_writer_pretty(file, &kv, config).unwrap();
tracing::trace!("Persisted to {:?}", file_path);
log::trace!("Persisted to {:?}", file_path);
});

self.last_save_join_handle = Some(join_handle);
Expand All @@ -104,7 +104,7 @@ where
match ron::de::from_reader(reader) {
Ok(value) => Some(value),
Err(err) => {
tracing::warn!("Failed to parse RON: {}", err);
log::warn!("Failed to parse RON: {}", err);
None
}
}
Expand Down
Loading

0 comments on commit 9c9a54c

Please sign in to comment.