From 389877bbbb03dbc7d2ff0d7c12d827b25542497f Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Sat, 8 Mar 2025 17:48:55 +0000 Subject: [PATCH 1/2] feat: Add logger to logger example --- examples/logging.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/logging.rs b/examples/logging.rs index d6a4e3575d..bc2153d9ad 100644 --- a/examples/logging.rs +++ b/examples/logging.rs @@ -11,10 +11,12 @@ //! //! To use the dioxus logger in your app, simply call any of the tracing functions (info!(), warn!(), error!()) -use dioxus::logger::tracing::{debug, error, info, warn}; +#[allow(unused_imports)] +use dioxus::logger::tracing::{debug, error, info, warn, Level}; use dioxus::prelude::*; fn main() { + dioxus::logger::init(Level::INFO).expect("Failed to initialize logger"); dioxus::launch(app); } @@ -31,7 +33,10 @@ fn app() -> Element { "Error!" } button { - onclick: move |_| debug!("Here's a debug"), + onclick: move |_| { + debug!("Here's a debug"); + warn!("The log level is set to info so there should not be a debug message") + }, "Debug!" } button { From a6d8ddb9129e6e9ed06fc44daeed34af5aee58c3 Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Sat, 5 Apr 2025 02:36:47 +0000 Subject: [PATCH 2/2] Add comment to logging example --- examples/logging.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/logging.rs b/examples/logging.rs index bc2153d9ad..1f75d47808 100644 --- a/examples/logging.rs +++ b/examples/logging.rs @@ -11,11 +11,16 @@ //! //! To use the dioxus logger in your app, simply call any of the tracing functions (info!(), warn!(), error!()) -#[allow(unused_imports)] use dioxus::logger::tracing::{debug, error, info, warn, Level}; use dioxus::prelude::*; fn main() { + // `dioxus::logger::init` is optional and called automatically by `dioxus::launch`. + // In development mode, the `Debug` tracing level is set, and in release only the `Info` level is set. + // You can call it yourself manually in the cases you: + // - want to customize behavior + // - aren't using `dioxus::launch` (i.e. custom fullstack setups) but want the integration. + // The Tracing crate is the logging interface that the dioxus-logger uses. dioxus::logger::init(Level::INFO).expect("Failed to initialize logger"); dioxus::launch(app); }