7 unstable releases (3 breaking)
0.6.2 | Jul 10, 2023 |
---|---|
0.6.1 | Jul 9, 2023 |
0.5.0 | Jul 9, 2023 |
0.4.0 | Jul 9, 2023 |
0.1.0 |
|
#21 in #insight
60 downloads per month
13KB
236 lines
A Logsnag API Wrapper for Rust
logsnag
is a simple and efficient Rust library for interacting with the Logsnag API. It supports asynchronous requests and allows easy publication of logs and insights.
Note: this crate is currently being actively developed. It may change a lot until v1.0. Keep this in mind if you're using it for production apps.
Features
- Publish logs to channels with specified event, optional description, icon, and notify flag
- Publish insights with a specified title, event, value, and an optional icon
- Support tags
- Support validation for inputs on the strings (some)
Getting Started
First, add logsnag
to your Cargo.toml
:
[dependencies]
logsnag = "0.6.2"
Then, import it in your file(s).
use logsnag::Logsnag;
Usage
Here is a basic example of how to use the Logsnag
client. It uses a builder to add on to the initial event/insight for the optional parameters. Anything that has with_
is an optional function. Note that for tags, you must add one at a time with with_tag()
:
use logsnag::Logsnag;
async fn main() {
let logsnag = Logsnag::new(
env::var("LOGSNAG_API_KEY").expect("No Logsnag API Key (LOGSNAG_API_KEY) found in Environment.")
env::var("LOGSNAG_PROJECT").expect("No Logsnag Project (LOGSNAG_PROJECT) found in Environment.")
);
let publish_result = logsnag.event("channel","event")
.with_notify(true)
.with_description("description")
.with_icon("❤️")
.with_tag("tag", "value")
.with_tag("tag2", "value2")
.publish()
.await;
let insight_result = logsnag.insight("title", "value") //value can be also an Int or a bool
.with_icon("🟢")
.publish()
.await;
}
Auto Validation
Tags have a specific format that they need to be in to pass correctly to publish an event. They need to be lowercase, have no special characters, no spaces, and no uppercase characters. Only dashes are allowed.
with_tag()
automatically will parse your text and strip the unwanted characters out to prevent runtime errors. There's not a currently known way to check validation on compile time within Rust, but if that changes we will implement it. If you know of a way to do this within functions let us know.
Docs
See the API Documentation for more details around the methods we use in this library.
Contributing
Please feel free to submit issues, fork the repository and send pull requests!
Any questions, you can find me (rhh4x0r) on the Official Logsnag Discord Server or submit an issue.
Dependencies
~8–25MB
~308K SLoC