[][src]Crate logdna_client

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

let mut rt = Runtime::new().expect("Runtime::new()");

The client requires a request template to generate new requests from

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

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

// 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

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

assert_eq!(Response::Sent, rt.block_on(response).unwrap())

Modules

body

Log line and body types

client

Http client

error

Error types

params

Query parameters

request

Request types

response

Response types