DOCUMENTATION

Appender for log4j

You can use the logify-alert-log4j library to send log4j log messages to Logify Alert.

Add the Library to Your Application

  1. Add the logify-alert-log4j library to your application.

    In the pom.xml file, do the following:

    1. In the dependencies section, declare the logify-alert-log4j library dependency:

      <dependency>
        <groupId>com.devexpress.logify</groupId>
        <artifactId>logify-alert-log4j</artifactId>
        <version>1.0.2</version>
      </dependency>
      

    2. In the repositories section, declare the Logify Alert's maven repository:

      <repository>
        <id>any-name-or-id</id>
        <url>https://github.com/DevExpress/Logify.Alert.Clients/raw/maven </url>
      </repository>
      

    In the build.gradle file, do the following:

    1. In the dependencies section, declare the logify-alert-log4j library dependency:

      compile "com.devexpress.logify:logify-alert-log4j:1.0.2"

    2. In the repositories section, declare the Logify Alert's maven repository:

      maven {
          url "https://github.com/DevExpress/Logify.Alert.Clients/raw/maven"
      }
      

  2. Synchronize your project.

Set Up the Logify Alert's Java Client

Configure the Logify Alert client in the logify.properties file or in your application's code.

# required
apiKey=YOUR_API_KEY

# optional
appName=YOUR_APP_NAME
appVersion=YOUR_APP_VERSION
userId=YOUR_USER_ID
customData=NAME_1:VALUE_1,NAME_2:VALUE_2,NAME_3:VALUE_3
tags=TAG_1:VALUE_1,TAG_2:VALUE_2

import com.devexpress.logify.alert.java.LogifyAlert;

LogifyAlert client = LogifyAlert.getInstance();
// required
client.setApiKey("YOUR_API_KEY");

// optional
client.setAppName("YOUR_APP_NAME");
client.setAppVersion("YOUR_APP_VERSION");
client.setUserId("YOUR_USER_ID");
client.addCustomData("NAME_1", "VALUE_1");
client.addTag("TAG_1", "VALUE_1");

Register an Appender

Register the LogifyAlertAppender as a standard log4j appender in the log4j.properties configuration file:

log4j.rootLogger=logifyalert
...
log4j.appender.logifyalert=com.devexpress.logify.alert.log4j.LogifyAlertAppender

Now a new report is generated and sent to Logify Alert each time your application calls the error log4j method with the LoggingEvent.getThrowableInformation() parameter. For example:

import org.apache.log4j.*;

public class Main {
    private final static Logger logger = LogManager.getRootLogger();

    public static void main(String[] args) {
    // ...
    logger.error("log4j test message", new Throwable("log4j test error"));
    }
}

Terms of use Copyright © 2016-2019 Developer Express Inc.