logdna-client 0.0.11

wrapper around LogDNA's Ingest API
Documentation

A client library for communicating with LogDNA's Ingest API

This crate heavily relies on Hyper and Tokio for it's operation. It is strongly recommend to read their respective docs for advanced usage of this crate.

Overview

The general flow is quite simple, first create a new client with Client::builder.

Then call Client::send as many times a you would like.

Example

You first need a Tokio Runtume

# use tokio::runtime::Runtime;
let mut rt = Runtime::new().expect("Runtime::new()");

The client requires a request template to generate new requests from

# use logdna_client::params::Params;
# use logdna_client::request::RequestTemplate;
# use std::env;
let params = Params::builder()
.hostname("rust-client-test")
.ip("127.0.0.1")
.tags("this,is,a,test")
.build()
.expect("Params::builder()");

let template = RequestTemplate::builder()
.host("logs.logdna.com")
.params(params)
.api_key("ingestion key goes here")
.build()
.expect("RequestTemplate::builder()");

Now you have everything to create a client

# use logdna_client::client::Client;
let client = Client::new(request_template, &mut rt);

To use a client, we need to call Client::send

Client::send requires an IngestBody, so let's create one

# use logdna_client::body::{Labels, Line, IngestBody};
// Lets build a line, note that only line is required
let labels = Labels::new()
.add("app", "test")
.add("workload", "test");

let line1 = Line::builder()
.line("this is a test")
.app("rust-client")
.level("INFO")
.labels(labels)
.build()
.expect("Line::builder()");

let line2 = Line::builder()
.line("this is also a test")
.app("rust-client")
.level("ERROR")
.build()
.expect("Line::builder()");

let body = IngestBody::new(vec![line1,line2]);

Now we just have to send the body using an the client you created above

# use  logdna_client::body::IngestBody;
let response = client.send(IngestBody::new(vec![line]));

The response needs to be spawned on the runtime you created earlier

If the reponse is not polled (spawned on a runtime) nothing will happen

# use logdna_client::response::Response;
assert_eq!(Response::Sent, rt.block_on(response).unwrap())