Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,28 @@ description = "log implementation for egui"
categories = ["gui", "game-development", "development-tools::debugging"]
include = ["src/*.rs", "Cargo.toml", "LICENSE"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
puffin = ["dep:puffin"]

[dependencies]
log = "0.4"
egui = "0.31"
regex = "1.11"
puffin = { version = "0.19", optional = true }

[dev-dependencies]
eframe = "0.31"
multi_log = "0.1"
env_logger = "0.11"
puffin_egui = { version = "0.29.0" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
chrono = { version = "0.4", default-features = false, features = ["alloc", "clock"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
chrono = { version = "0.4", default-features = false, features = ["alloc", "clock", "wasmbind"] }

[patch.crates-io]
# It seems that puffin and puffin_egui are really outdated
puffin = { git = "https://github.com/tedsteen/puffin", branch = "upgrade-egui" }
puffin_egui = { git = "https://github.com/tedsteen/puffin", branch = "upgrade-egui" }
59 changes: 59 additions & 0 deletions examples/puffin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This example needs the puffin feature enabled to work
// you can test this with:
// cargo run --example puffin --features puffin


use eframe::NativeOptions;
use puffin_egui::puffin;

fn main() {
puffin::set_scopes_on(true);
// Initialize the logger
egui_logger::builder()
.init()
.expect("Error initializing logger");

let options = NativeOptions::default();

eframe::run_native("egui_logger", options, Box::new(|_cc| Ok(Box::new(MyApp)))).unwrap();
}

#[derive(Default)]
struct MyApp;

impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
puffin::GlobalProfiler::lock().new_frame();
puffin_egui::profiler_window(ctx);
egui::CentralPanel::default().show(ctx, |ui| {
#[cfg(feature = "puffin")]
puffin::profile_scope!("Render UI");
if ui.button("This produces Debug Info").clicked() {
log::debug!("Very verbose Debug Info")
}
if ui.button("This produces an Info").clicked() {
log::info!("Some Info");
}
if ui.button("This produces an Error").clicked() {
log::error!("Error doing Something");
}
if ui.button("This produces a Warning").clicked() {
log::warn!("Warn about something")
}
if ui.button("This produces 1000 Warnings").clicked() {
(1..1000).for_each(|x| log::warn!("Warn: {}",x));
log::warn!("Warn about something")
}
if ui.button("This produces 100_000 Warnings").clicked() {
(1..100_000).for_each(|x| log::warn!("Warn: {}",x));
log::warn!("Warn about something")
}
});
egui::Window::new("Log").show(ctx, |ui| {
// draws the actual logger ui
egui_logger::LoggerUi::default()
.enable_regex(true) // enables regex, default is true
.show(ui)
});
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ impl log::Log for EguiLogger {
}

fn log(&self, record: &log::Record) {
#[cfg(feature = "puffin")]
puffin::profile_scope!("Lock Mutex");
if self.enabled(record.metadata()) {
if let Ok(ref mut logger) = LOGGER.lock() {
logger.logs.push(Record {
Expand Down
2 changes: 2 additions & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ impl LoggerUi {
}

pub(crate) fn ui(&mut self, ui: &mut egui::Ui) {
#[cfg(feature = "puffin")]
puffin::profile_scope!("render logger UI");
let Ok(ref mut logger) = LOGGER.lock() else {
return;
};
Expand Down
Loading