Java Util
First add a dependency on the r7insight_java library, maven users copy the following into your pom.xml.
<dependency>
<groupId>com.rapid7</groupId>
<artifactId>r7insight_java</artifactId>
<version>RELEASE</version>
</dependency>
You will need to include your logging token, region (e.g. “us” or “eu”), and formatter in a properties file:
handlers = com.rapid7.jul.LogentriesHandler
.handlers = com.rapid7.jul.LogentriesHandler
com.rapid7.jul.LogentriesHandler.token = e1786e4f-c4f7-40c7-94c2-5f84b1cce122
com.rapid7.jul.LogentriesHandler.region = eu
com.rapid7.jul.LogentriesHandler.formatter = java.util.logging.SimpleFormatter
You will need these imports.
import java.util.logging.LogManager;
import java.util.logging.Logger;
Get a LogManager.
private static LogManager logManager = LogManager.getLogManager();
Configure the log manager with the properties file, it will point it at the LogentriesHandler class.
InputStream is = new FileInputStream("src/main/resources/logging.properties");
logManager.readConfiguration(is);
Get the logger.
Logger log = logManager.getLogger("global");
Use it to send logs.
log.info("info logging message goes here");
log.warning("warning logging message goes here");