mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Replace tracing with log (#2928)
* 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
This commit is contained in:
@@ -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 {
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ fn run_and_return(
|
||||
) -> Result<()> {
|
||||
use winit::platform::run_return::EventLoopExtRunReturn as _;
|
||||
|
||||
tracing::debug!("Entering the winit event loop (run_return)…");
|
||||
log::debug!("Entering the winit event loop (run_return)…");
|
||||
|
||||
let mut next_repaint_time = Instant::now();
|
||||
|
||||
@@ -126,7 +126,7 @@ fn run_and_return(
|
||||
winit::event::Event::LoopDestroyed => {
|
||||
// On Mac, Cmd-Q we get here and then `run_return` doesn't return (despite its name),
|
||||
// so we need to save state now:
|
||||
tracing::debug!("Received Event::LoopDestroyed - saving app state…");
|
||||
log::debug!("Received Event::LoopDestroyed - saving app state…");
|
||||
winit_app.save_and_destroy();
|
||||
*control_flow = ControlFlow::Exit;
|
||||
return;
|
||||
@@ -161,7 +161,7 @@ fn run_and_return(
|
||||
event => match winit_app.on_event(event_loop, event) {
|
||||
Ok(event_result) => event_result,
|
||||
Err(err) => {
|
||||
tracing::error!("Exiting because of error: {err:?} on event {event:?}");
|
||||
log::error!("Exiting because of error: {err:?} on event {event:?}");
|
||||
returned_result = Err(err);
|
||||
EventResult::Exit
|
||||
}
|
||||
@@ -171,7 +171,7 @@ fn run_and_return(
|
||||
match event_result {
|
||||
EventResult::Wait => {}
|
||||
EventResult::RepaintNow => {
|
||||
tracing::trace!("Repaint caused by winit::Event: {:?}", event);
|
||||
log::trace!("Repaint caused by winit::Event: {:?}", event);
|
||||
if cfg!(windows) {
|
||||
// Fix flickering on Windows, see https://github.com/emilk/egui/pull/2280
|
||||
next_repaint_time = Instant::now() + Duration::from_secs(1_000_000_000);
|
||||
@@ -182,14 +182,14 @@ fn run_and_return(
|
||||
}
|
||||
}
|
||||
EventResult::RepaintNext => {
|
||||
tracing::trace!("Repaint caused by winit::Event: {:?}", event);
|
||||
log::trace!("Repaint caused by winit::Event: {:?}", event);
|
||||
next_repaint_time = Instant::now();
|
||||
}
|
||||
EventResult::RepaintAt(repaint_time) => {
|
||||
next_repaint_time = next_repaint_time.min(repaint_time);
|
||||
}
|
||||
EventResult::Exit => {
|
||||
tracing::debug!("Asking to exit event loop…");
|
||||
log::debug!("Asking to exit event loop…");
|
||||
winit_app.save_and_destroy();
|
||||
*control_flow = ControlFlow::Exit;
|
||||
return;
|
||||
@@ -210,7 +210,7 @@ fn run_and_return(
|
||||
}
|
||||
});
|
||||
|
||||
tracing::debug!("eframe window closed");
|
||||
log::debug!("eframe window closed");
|
||||
|
||||
drop(winit_app);
|
||||
|
||||
@@ -224,14 +224,14 @@ fn run_and_return(
|
||||
}
|
||||
|
||||
fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp + 'static) -> ! {
|
||||
tracing::debug!("Entering the winit event loop (run)…");
|
||||
log::debug!("Entering the winit event loop (run)…");
|
||||
|
||||
let mut next_repaint_time = Instant::now();
|
||||
|
||||
event_loop.run(move |event, event_loop, control_flow| {
|
||||
let event_result = match event {
|
||||
winit::event::Event::LoopDestroyed => {
|
||||
tracing::debug!("Received Event::LoopDestroyed");
|
||||
log::debug!("Received Event::LoopDestroyed");
|
||||
EventResult::Exit
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
|
||||
next_repaint_time = next_repaint_time.min(repaint_time);
|
||||
}
|
||||
EventResult::Exit => {
|
||||
tracing::debug!("Quitting - saving app state…");
|
||||
log::debug!("Quitting - saving app state…");
|
||||
winit_app.save_and_destroy();
|
||||
#[allow(clippy::exit)]
|
||||
std::process::exit(0);
|
||||
@@ -410,7 +410,7 @@ mod glow_integration {
|
||||
config_template_builder
|
||||
};
|
||||
|
||||
tracing::debug!(
|
||||
log::debug!(
|
||||
"trying to create glutin Display with config: {:?}",
|
||||
&config_template_builder
|
||||
);
|
||||
@@ -426,7 +426,7 @@ mod glow_integration {
|
||||
let config = config_iterator.next().expect(
|
||||
"failed to find a matching configuration for creating glutin config",
|
||||
);
|
||||
tracing::debug!(
|
||||
log::debug!(
|
||||
"using the first config from config picker closure. config: {:?}",
|
||||
&config
|
||||
);
|
||||
@@ -436,13 +436,13 @@ mod glow_integration {
|
||||
.map_err(|e| crate::Error::NoGlutinConfigs(config_template_builder.build(), e))?;
|
||||
|
||||
let gl_display = gl_config.display();
|
||||
tracing::debug!(
|
||||
log::debug!(
|
||||
"successfully created GL Display with version: {} and supported features: {:?}",
|
||||
gl_display.version_string(),
|
||||
gl_display.supported_features()
|
||||
);
|
||||
let raw_window_handle = window.as_ref().map(|w| w.raw_window_handle());
|
||||
tracing::debug!(
|
||||
log::debug!(
|
||||
"creating gl context using raw window handle: {:?}",
|
||||
raw_window_handle
|
||||
);
|
||||
@@ -459,8 +459,8 @@ mod glow_integration {
|
||||
{
|
||||
Ok(it) => it,
|
||||
Err(err) => {
|
||||
tracing::warn!("failed to create context using default context attributes {context_attributes:?} due to error: {err}");
|
||||
tracing::debug!("retrying with fallback context attributes: {fallback_context_attributes:?}");
|
||||
log::warn!("failed to create context using default context attributes {context_attributes:?} due to error: {err}");
|
||||
log::debug!("retrying with fallback context attributes: {fallback_context_attributes:?}");
|
||||
gl_config
|
||||
.display()
|
||||
.create_context(&gl_config, &fallback_context_attributes)?
|
||||
@@ -494,15 +494,13 @@ mod glow_integration {
|
||||
#[allow(unsafe_code)]
|
||||
fn on_resume(&mut self, event_loop: &EventLoopWindowTarget<UserEvent>) -> Result<()> {
|
||||
if self.gl_surface.is_some() {
|
||||
tracing::warn!(
|
||||
"on_resume called even thought we already have a surface. early return"
|
||||
);
|
||||
log::warn!("on_resume called even thought we already have a surface. early return");
|
||||
return Ok(());
|
||||
}
|
||||
tracing::debug!("running on_resume fn.");
|
||||
log::debug!("running on_resume fn.");
|
||||
// make sure we have a window or create one.
|
||||
let window = self.window.take().unwrap_or_else(|| {
|
||||
tracing::debug!("window doesn't exist yet. creating one now with finalize_window");
|
||||
log::debug!("window doesn't exist yet. creating one now with finalize_window");
|
||||
glutin_winit::finalize_window(event_loop, self.builder.clone(), &self.gl_config)
|
||||
.expect("failed to finalize glutin window")
|
||||
});
|
||||
@@ -513,7 +511,7 @@ mod glow_integration {
|
||||
let surface_attributes =
|
||||
glutin::surface::SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new()
|
||||
.build(window.raw_window_handle(), width, height);
|
||||
tracing::debug!(
|
||||
log::debug!(
|
||||
"creating surface with attributes: {:?}",
|
||||
&surface_attributes
|
||||
);
|
||||
@@ -523,7 +521,7 @@ mod glow_integration {
|
||||
.display()
|
||||
.create_window_surface(&self.gl_config, &surface_attributes)?
|
||||
};
|
||||
tracing::debug!("surface created successfully: {gl_surface:?}.making context current");
|
||||
log::debug!("surface created successfully: {gl_surface:?}.making context current");
|
||||
// make surface and context current.
|
||||
let not_current_gl_context = self
|
||||
.not_current_gl_context
|
||||
@@ -531,9 +529,9 @@ mod glow_integration {
|
||||
.expect("failed to get not current context after resume event. impossible!");
|
||||
let current_gl_context = not_current_gl_context.make_current(&gl_surface)?;
|
||||
// try setting swap interval. but its not absolutely necessary, so don't panic on failure.
|
||||
tracing::debug!("made context current. setting swap interval for surface");
|
||||
log::debug!("made context current. setting swap interval for surface");
|
||||
if let Err(e) = gl_surface.set_swap_interval(¤t_gl_context, self.swap_interval) {
|
||||
tracing::error!("failed to set swap interval due to error: {e:?}");
|
||||
log::error!("failed to set swap interval due to error: {e:?}");
|
||||
}
|
||||
// we will reach this point only once in most platforms except android.
|
||||
// create window/surface/make context current once and just use them forever.
|
||||
@@ -545,16 +543,14 @@ mod glow_integration {
|
||||
|
||||
/// only applies for android. but we basically drop surface + window and make context not current
|
||||
fn on_suspend(&mut self) -> Result<()> {
|
||||
tracing::debug!("received suspend event. dropping window and surface");
|
||||
log::debug!("received suspend event. dropping window and surface");
|
||||
self.gl_surface.take();
|
||||
self.window.take();
|
||||
if let Some(current) = self.current_gl_context.take() {
|
||||
tracing::debug!("context is current, so making it non-current");
|
||||
log::debug!("context is current, so making it non-current");
|
||||
self.not_current_gl_context = Some(current.make_not_current()?);
|
||||
} else {
|
||||
tracing::debug!(
|
||||
"context is already not current??? could be duplicate suspend event"
|
||||
);
|
||||
log::debug!("context is already not current??? could be duplicate suspend event");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -952,7 +948,7 @@ mod glow_integration {
|
||||
winit::event::WindowEvent::CloseRequested
|
||||
if running.integration.should_close() =>
|
||||
{
|
||||
tracing::debug!("Received WindowEvent::CloseRequested");
|
||||
log::debug!("Received WindowEvent::CloseRequested");
|
||||
return Ok(EventResult::Exit);
|
||||
}
|
||||
_ => {}
|
||||
@@ -1375,7 +1371,7 @@ mod wgpu_integration {
|
||||
winit::event::WindowEvent::CloseRequested
|
||||
if running.integration.should_close() =>
|
||||
{
|
||||
tracing::debug!("Received WindowEvent::CloseRequested");
|
||||
log::debug!("Received WindowEvent::CloseRequested");
|
||||
return Ok(EventResult::Exit);
|
||||
}
|
||||
_ => {}
|
||||
|
||||
Reference in New Issue
Block a user