Skip to content

Commit b6243d3

Browse files
authored
feat: Add logger to logger example (#3846)
* feat: Add logger to logger example * Add comment to logging example
1 parent 3da821d commit b6243d3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

examples/logging.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@
1111
//!
1212
//! To use the dioxus logger in your app, simply call any of the tracing functions (info!(), warn!(), error!())
1313
14-
use dioxus::logger::tracing::{debug, error, info, warn};
14+
use dioxus::logger::tracing::{debug, error, info, warn, Level};
1515
use dioxus::prelude::*;
1616

1717
fn main() {
18+
// `dioxus::logger::init` is optional and called automatically by `dioxus::launch`.
19+
// In development mode, the `Debug` tracing level is set, and in release only the `Info` level is set.
20+
// You can call it yourself manually in the cases you:
21+
// - want to customize behavior
22+
// - aren't using `dioxus::launch` (i.e. custom fullstack setups) but want the integration.
23+
// The Tracing crate is the logging interface that the dioxus-logger uses.
24+
dioxus::logger::init(Level::INFO).expect("Failed to initialize logger");
1825
dioxus::launch(app);
1926
}
2027

@@ -31,7 +38,10 @@ fn app() -> Element {
3138
"Error!"
3239
}
3340
button {
34-
onclick: move |_| debug!("Here's a debug"),
41+
onclick: move |_| {
42+
debug!("Here's a debug");
43+
warn!("The log level is set to info so there should not be a debug message")
44+
},
3545
"Debug!"
3646
}
3747
button {

0 commit comments

Comments
 (0)