[![maven](https://img.shields.io/maven-central/v/io.hackerbay.fyipe/java-sdk)](https://search.maven.org/artifact/io.hackerbay.fyipe/java-sdk) # Fyipe SDK A fyipe sdk for application logger that can be used to send logs about your applications created on your fypie dashboard which can also used for error tracking ## Installation ### Maven Install You can install to use in your project by adding the following to your `pom.xml` file: ```xml io.hackerbay.fyipe java-sdk CURRENT_VERSION ``` ### Others Check [Maven Central Repository](https://search.maven.org/artifact/io.hackerbay.fyipe/java-sdk) for other modes of installation. ## Basic Usage for Logging ```java import com.google.gson.JsonObject; import io.hackerbay.fyipe.FyipeLogger; import java.io.IOException; public class SampleClass { // set up the FyipeLogger public FyipeLogger logger = new FyipeLogger( "API_URL", // https://fyipe.com/api "APPLICATION_LOG_ID", "APPLICATION_LOG_KEY" ); // Logging a string information public void logStringInformation() throws IOException { String content = "Content to be logged"; JsonObject response = logger.log(content); // returns a JsonObject of response System.out.println(response); } // Logging any object of a class public void logACustomClassInformation(CustomClass customClass) throws IOException { String content = new Gson().toJson(customClass); // converts your custom class to a json object JsonObject response = logger.log(content); // returns a JsonObject of response System.out.println(response); } // Logging a string with a series of tags public void logStringInformation() throws IOException { String content = "Content to be logged"; String [] tags = { "server", "monitoring", "logs" }; JsonObject response = logger.log(content, tags); // returns a JsonObject of response System.out.println(response); } } ``` ## Basic Usage for Tracking ```java import com.google.gson.JsonObject; import io.hackerbay.fyipe.FyipeTracker; import java.io.IOException; import io.hackerbay.fyipe.model.Tag; import io.hackerbay.fyipe.model.TrackerOption; public class SampleClass { // set up option TrackerOption trackerOption = new TrackerOption(50); // set maximum timeline per event // set up the FyipeTracker public FyipeTracker tracker = new FyipeTracker( "API_URL", // https://fyipe.com/api "ERROR_TRACKER_ID", "ERROR_TRACKER_KEY", trackerOption ); // set up a timeline to be recorded JsonObject object = new JsonObject(); object.addProperty("account", "debit"); object.addProperty("amount", "6000.00"); object.addProperty("userId", 471); tracker.addToTimeline("cart", object ," info"); // setting custom tags Tag tag = new Tag("category", "customer"); tracker.setTag(tag); // a single tag // multiple tags ArrayList sampleTags = new ArrayList(); // create two tags and add to the array sampleTags.add(new Tag("type", "notification")); sampleTags.add(new Tag("location", "Oslo")); // setting the array of tags tracker.setTags(sampleTags); // capturing errors in a try and catch try { // some code that might fail } catch(Exception e) { tracker.captureException(e); // this is sent to your fyipe dashboard } // capturing errors using the message signature tracker.captureMessage('some error text'); // capturing errors authomatically throw new Exception("Something went wrong"); // calling this will trigger an error and its sent to your fyipe dashboard } ``` ## API Documentation Main API to send logs to the server. **Author**: HackerBay, Inc. - [Fyipe SDK](#fyipe-sdk) - [Installation](#installation) - [Maven Install](#maven-install) - [Others](#others) - [Basic Usage for Logging](#basic-usage-for-logging) - [Basic Usage for Tracking](#basic-usage-for-tracking) - [API Documentation](#api-documentation) - [new FyipeLogger(apiUrl, applicationId, applicationKey)](#new-fyipeloggerapiurl-applicationid-applicationkey) - [logger.log(log, tags)](#loggerloglog-tags) - [logger.warning(warning, tags)](#loggerwarningwarning-tags) - [logger.error(error, tags)](#loggererrorerror-tags) - [new FyipeTracker(apiUrl, errorTrackerId, errorTrackerKey, option)](#new-fyipetrackerapiurl-errortrackerid-errortrackerkey-option) - [TrackerOption options](#trackeroption-options) - [tracker.setTag(Tag tag)](#trackersettagtag-tag) - [tracker.setTags(ArrayList tags)](#trackersettagsarraylisttag-tags) - [tracker.setFingerprint(ArrayList fingerprints)](#trackersetfingerprintarrayliststring-fingerprints) - [tracker.addToTimeline(category, content, type)](#trackeraddtotimelinecategory-content-type) - [tracker.captureMessage(message)](#trackercapturemessagemessage) - [tracker.captureException(error)](#trackercaptureexceptionerror) - [Contribution](#contribution) ### new FyipeLogger(apiUrl, applicationId, applicationKey) Create a constructor from the class, which will be used to send logs to the server. **Kind**: Constructor **Returns**: null | Param | Type | Description | | -------------- | ------------------- | ------------------------ | | apiUrl | String | The Server URL. | | applicationId | String | The Application Log ID. | | applicationKey | String | The Application Log Key. | #### logger.log(log, tags) Logs a request of type `info` to the server. **Kind**: method of [new FyipeLogger](#logger_api--logger) **Returns**: JsonObject - A response of a success or failure. | Param | Type | Description | | ----- | --------------------- | ----------------------------------------------------------- | | log | String | The content to the logged on the server. | | tags | String[] | The tag(s) to be attached to the logged item on the server. | #### logger.warning(warning, tags) Logs a request of type `warning` to the server. **Kind**: method of [new FyipeLogger](#logger_api--logger) **Returns**: JsonObject - A response of a success or failure. | Param | Type | Description | | ------- | --------------------- | ----------------------------------------------------------- | | warning | String | The content to the logged on the server. | | tags | String[] | The tag(s) to be attached to the logged item on the server. | #### logger.error(error, tags) Logs a request of type `error` to the server. **Kind**: method of [new FyipeLogger](#logger_api--logger) **Returns**: JsonObject - A response of a success or failure. | Param | Type | Description | | ----- | --------------------- | ----------------------------------------------------------- | | error | String | The content to the logged on the server. | | tags | String[] | The tag(s) to be attached to the logged item on the server. | ### new FyipeTracker(apiUrl, errorTrackerId, errorTrackerKey, option) Create a constructor from the class, which will be used to track errors sent to the server. **Kind**: Constructor **Returns**: null | Param | Type | Description | | --------------- | -------------------------- | ------------------------------------------- | | apiUrl | string | The Server URL. | | errorTrackerId | string | The Error Tracker ID. | | errorTrackerKey | string | The Error Trakcer Key. | | option | TrackerOption | The options to be considred by the tracker. | #### TrackerOption options | Param | Type | Description | | ----------- | ---------------- | ------------------------------------------------------------------- | | maxTimeline | int | The total amount of timeline that should be captured, defaults to 5 | #### tracker.setTag(Tag tag) Set tag for the error to be sent to the server. **Kind**: method of [new Fyipe\FyipeTracker](#tracker_api--tracker) **Returns**: null | Param | Type | Description | | ----- | ---------------- | --------------- | | tag | Tag | The tag object. | #### tracker.setTags(ArrayList tags) Set multiple tags for the error to be sent to the server. Takes in an array **Kind**: method of [new Fyipe\FyipeTracker](#tracker_api--tracker) **Returns**: null | Param | Type | Description | | ----- | ----------------------------- | -------------------------------------------- | | tags | ArrayList of Tag | The list of tags to be added to the tracker. | #### tracker.setFingerprint(ArrayList fingerprints) Set fingerprint for the next error to be captured. **Kind**: method of [new Fyipe\FyipeTracker](#tracker_api--tracker) **Returns**: null | Param | Type | Description | | ----------- | -------------------------------------------------------- | ------------------------------------------------------------- | | fingerprint | string \| ArrayList of strings | The set of string used to group error messages on the server. | #### tracker.addToTimeline(category, content, type) Add a custom timeline element to the next error to be sent to the server **Kind**: method of [new Fyipe\FyipeTracker](#tracker_api--tracker) **Returns**: null | Param | Type | Description | | -------- | ----------------------- | ----------------------------------- | | category | string | The category of the timeline event. | | content | JsonObject | The content of the timeline event. | | type | string | The type of timeline event. | #### tracker.captureMessage(message) Capture a custom error message to be sent to the server **Kind**: method of [new Fyipe\FyipeTracker](#tracker_api--tracker) **Returns**: Promise | Param | Type | Description | | -------- | ------------------- | ------------------------------------- | | \message | string | The message to be sent to the server. | #### tracker.captureException(error) Capture a custom error object to be sent to the server **Kind**: method of [new Fyipe\FyipeTracker](#tracker_api--tracker) **Returns**: Promise | Param | Type | Description | | ------ | ---------------------- | ------------------------------------------ | | \error | Throwable | The Error Object to be sent to the server. | ## Contribution - Clone repository - run `mvn clean install` to install dependencies - run `mvn test` to run tests - run `mvn package` to build for production.