Our next-gen architecture is built to help you make sense of your ever-growing data Watch a 4-min demo video!

Back to All Integrations

Java Java

Last Updated: Aug. 16, 2022

We believe you should no be limited to application based file shippers.

So to support such cases where you want to integrate you application to Coralogix on the basic code level we provide easy to use SDKs.

Our SDKs will integrate with the basic logger functions and will also offer appenders support for Java.

We support Maven repository.

Requirements

  • A Private Key – You can find your key in your Coralogix account under ‘Data Flow’ -> ‘API Keys’ -> ‘Send your logs’.
  • Company ID – You can find your company Id from the ‘Settings’ -> ‘Send Your Data’ : company ID will be on the top right.
  • Add the ‘Coralogix SDK’ to your project dependencies.

As we use Artifactory as our repository you will need to also add a repository to your pom.xml file:

  <repositories>
    <repository>
        <id>coralogix</id>
        <name>coralogix repo</name>
        <url>https://cgx.jfrog.io/artifactory/maven</url>
    </repository>
  </repositories>

Then, add the dependency to your pom.xml file:

  <dependencies>
    <dependency>
      <groupId>com.coralogix.sdk</groupId>
      <artifactId>coralogix-sdk</artifactId>
      <version>2.0.10</version>
    </dependency>
  </dependencies>

If your Account is not in the EU region (the account url does not have a .com suffix)

you will need to add this environment variable (where the code will run):

CORALOGIX_LOG_URL=https://<coralogix-api-url>/api/v1/logs
Account URLCoralogix API URL
coralogix.comapi.coralogix.com
coralogix.usapi.coralogix.us
eu2.coralogix.comapi.eu2.coralogix.com
app.coralogix.inapi.app.coralogix.in
coralogixsg.comapi.coralogixsg.com

Usage

Code Example for SDK versions 2.x

import api.CoralogixLogger; //import the SDK

public class logging {

    public static void main(String[] args) {
        String privateKey = "*insert your account private key*";
        String appName = "*Insert desired Application name*";
        String subSystem = "*Insert desired subsystem name*";

        CoralogixLogger.configure(privateKey, appName, subSystem); //Create a connection object to Coralogix
        CoralogixLogger logger = new CoralogixLogger(logging.class.toString()); //Create a generic logger object which the Coralogix SDK

        logger.info("my info log"); //Test the log shipping
    }
}

Code Example for SDK versions 1.x

For legacy support you can still use the old SDK version.

import com.coralogix.sdk.api.CoralogixLogger; //import the SDK
import com.coralogix.sdk.api.CoralogixSDK; //import the SDK

public class logging {
    public static void main(String[] args) throws Exception{

        String privateKey = "*insert the private key you received after signup*";
        int companyId = "*insert the company ID you received after signup*";
        String appName = *companyId* + "*Insert desired Application name*";
        String subsystem = "*Insert desired subsystem name*";

        CoralogixLogger logger = CoralogixSDK.createAndConnectNewLogger(appName, subsystem, companyId, privateKey); //Create a connection object to Coralogix
        logger.sendCriticalLog("This is my serious test log 1"); //Test the log shipping
    }
}

On this page