Java Util
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
1handlers = com.rapid7.jul.LogentriesHandler2.handlers = com.rapid7.jul.LogentriesHandler34com.rapid7.jul.LogentriesHandler.token = e1786e4f-c4f7-40c7-94c2-5f84b1cce1225com.rapid7.jul.LogentriesHandler.region = eu6com.rapid7.jul.LogentriesHandler.formatter = java.util.logging.SimpleFormatter
You will need these imports.
text
1import java.util.logging.LogManager;2import java.util.logging.Logger;
Get a LogManager.
text
1private static LogManager logManager = LogManager.getLogManager();
Configure the log manager with the properties file, it will point it at the LogentriesHandler class.
text
1InputStream is = new FileInputStream("src/main/resources/logging.properties");2logManager.readConfiguration(is);
Get the logger.
text
1Logger log = logManager.getLogger("global");
Use it to send logs.
text
1log.info("info logging message goes here");2log.warning("warning logging message goes here");
Did this page help you?