Java

LogHive provides a simple REST API that you can use to push events and errors. Here is an example code for Java:

Push Event

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpHeaders;
import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpRequest.BodyPublishers;
import java.util.Map;

public class HttpClientExample {

    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.loghive.app/v1/event/add"))
                .header("Content-Type", "application/json")
                .header("Authorization", "ApiKey: your-api-key")
                .POST(BodyPublishers.ofString("{\"project\":\"yourprojectname\", \"group\":\"yourgroupname\",\"event\":\"your-event-name\",\"description\":\"your-description\",\"notify\":false}"))
                .build();

        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

        System.out.println("Status code: " + response.statusCode());
        System.out.println("Response headers: " + response.headers().map());
        System.out.println("Response body: " + response.body());
    }
}

Push Insight

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpHeaders;
import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpRequest.BodyPublishers;
import java.util.Map;

public class HttpClientExample {

    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.loghive.app/v1/insight/add"))
                .header("Content-Type", "application/json")
                .header("Authorization", "ApiKey: your-api-key")
                .POST(BodyPublishers.ofString("{\"project\":\"MySaas\", \"insight\":\"system1-online\",\"value\":1}"))
                .build();

        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

        System.out.println("Status code: " + response.statusCode());
        System.out.println("Response headers: " + response.headers().map());
        System.out.println("Response body: " + response.body());
    }
}

Last updated