Java Util

Build Status

First add a dependency on the r7insight_java library, maven users copy the following into your pom.xml.

text
1
<dependency>
2
<groupId>com.rapid7</groupId>
3
<artifactId>r7insight_java</artifactId>
4
<version>RELEASE</version>
5
</dependency>

You will need to include your logging token, region (e.g. "us" or "eu"), and formatter in a properties file:

text
1
handlers = com.rapid7.jul.LogentriesHandler
2
.handlers = com.rapid7.jul.LogentriesHandler
3
4
com.rapid7.jul.LogentriesHandler.token = e1786e4f-c4f7-40c7-94c2-5f84b1cce122
5
com.rapid7.jul.LogentriesHandler.region = eu
6
com.rapid7.jul.LogentriesHandler.formatter = java.util.logging.SimpleFormatter

You will need these imports.

text
1
import java.util.logging.LogManager;
2
import java.util.logging.Logger;

Get a LogManager.

text
1
private static LogManager logManager = LogManager.getLogManager();

Configure the log manager with the properties file, it will point it at the LogentriesHandler class.

text
1
InputStream is = new FileInputStream("src/main/resources/logging.properties");
2
logManager.readConfiguration(is);

Get the logger.

text
1
Logger log = logManager.getLogger("global");

Use it to send logs.

text
1
log.info("info logging message goes here");
2
log.warning("warning logging message goes here");