Documentation

Java log4j Integration

Alooma supports a log4j interface that allows you to send events directly from your Java code quickly and easily.

Step 1 - Configure the Alooma Reporter

In your log4j2.xml add the following lines:

  1. In the <Appenders></Appenders> section:

    Copy
    <Socket name="Alooma" host="inputs.alooma.com" port="5001" 
    protocol="SSL">
    <PatternLayout pattern="%m%n" />
    </Socket> 
    
  2. In the <Loggers></Loggers> section:

    Copy
    <Logger name="alooma-reporter" level="debug" additivity="false">
      <AppenderRef ref="Alooma" />
    </Logger>

Step 2 - Send events using the Alooma reporter

  1. Log in to your Alooma account and add an "Java App" input.

  2. Give your input a name and copy the generated token.

  3. In your application code, initialize the reporter using the token from step 2:

    private static final Logger reporter = LogManager.getLogger("alooma-reporter");

    To send an event to Alooma:

    Copy
    reporter.info("{
        \"token\":\"YOUR_TOKEN\",
        \"message\":{\"stringField\":\"hello\",\"numField\":42}
      }"
    );

Note

The parameter passed to the info function should be a valid JSON object, encoded as a string. It may contain any field you like, including nested fields. It is recommended that you include a field called "type" which identifies the event type.

For more details about the logger and format used see the docs for SocketAppender and JSONLayout.

Search results

    No results found