1
0

logging.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //! Dioxus ships out-of-the-box with tracing hooks that integrate with the Dioxus-CLI.
  2. //!
  3. //! The built-in tracing-subscriber automatically sets up a wasm panic hook and wires up output
  4. //! to be consumed in a machine-readable format when running under `dx`.
  5. //!
  6. //! You can disable the built-in tracing-subscriber or customize the log level yourself.
  7. //!
  8. //! By default:
  9. //! - in `dev` mode, the default log output is `debug`
  10. //! - in `release` mode, the default log output is `info`
  11. //!
  12. //! To use the dioxus logger in your app, simply call any of the tracing functions (info!(), warn!(), error!())
  13. use dioxus::logger::tracing::{debug, error, info, warn};
  14. use dioxus::prelude::*;
  15. fn main() {
  16. dioxus::launch(app);
  17. }
  18. fn app() -> Element {
  19. rsx! {
  20. div {
  21. h1 { "Logger demo" }
  22. button {
  23. onclick: move |_| warn!("Here's a warning!"),
  24. "Warn!"
  25. }
  26. button {
  27. onclick: move |_| error!("Here's an error!"),
  28. "Error!"
  29. }
  30. button {
  31. onclick: move |_| debug!("Here's a debug"),
  32. "Debug!"
  33. }
  34. button {
  35. onclick: move |_| info!("Here's an info!"),
  36. "Info!"
  37. }
  38. }
  39. }
  40. }