7 unstable releases (3 breaking)
0.4.1 | May 8, 2023 |
---|---|
0.4.0 | May 7, 2023 |
0.3.0 | Nov 10, 2022 |
0.2.0 | Nov 9, 2022 |
0.1.2 | Nov 5, 2022 |
#129 in Debugging
2,187 downloads per month
Used in 2 crates
9KB
64 lines
📡 Dioxus Logger 🛰️
A logging utility to provide a standard interface whether you're targetting web, desktop, or mobile with Dioxus.
dioxus-logger
is a (planned-to-be) feature-rich logger for Dioxus that uses the log crate to provide a standard interface for all your logging needs.
Current & Planned Features
- stdio logging (Web, Desktop) - Mobile to come
- Custom log format - Basic Implementation Finished
- Timestamps
- Sending logs over HTTP to an API
- Logging to a file
- Logging to Sentry?
This library is not finished. Breaking changes may occur.
use dioxus::prelude::*;
use log::{info, LevelFilter};
fn main() {
dioxus_logger::init(LevelFilter::Info).expect("failed to init logger");
dioxus_web::launch(app);
}
fn app(cx: Scope) -> Element {
info!("my app component just rendered!");
cx.render(rsx!(p { "Hello, Dioxus!" }))
}
Platform Support
Dioxus logger will eventually support every target that Dioxus does. Currently only web and desktop platforms are supported.
Installation
You can add dioxus-logger
to your application by adding it to your dependencies.
[dependencies]
dioxus-logger = "x.x.x"
To use dioxus-logger as is, add this line before launching Dioxus, replacing LevelFilter::Info
with your preferred log level.
dioxus_logger::init(LevelFilter::Info).expect("failed to init logger");
Custom Format
Initialize dioxus-logger using the builder:
dioxus_logger::DioxusLogger::new(LevelFilter::Info)
.use_format("[{LEVEL}] {PATH} - {ARGS}")
.build()
.expect("failed to init logger");
The available options for use_format
are:
- LEVEL - The log severity.
- PATH - Which crate emitted the log.
- ARGS - The text that was logged.
- TIMESTAMP - A timestamp of when the log was emitted. Requires the
timestamps
feature.
Surround the option with {}
in the use_format
method.
License
This project is licensed under the MIT license.
Every contribution intentionally submitted
for inclusion in dioxus-logger
by you, shall be licensed as MIT, without any additional
terms or conditions.
Dependencies
~6.5–9MB
~173K SLoC