Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Java Util Logging

Safa Topal edited this page Apr 10, 2017 · 5 revisions

Build Status Java Util Logging

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

<dependency>
    <groupId>com.logentries</groupId>
    <artifactId>logentries-appender</artifactId>
    <version>1.1.29</version>
</dependency>

You will need to include your logging token, port, endpoint and formatter in a properties file, a sample is included in this repository here.

handlers = com.logentries.jul.LogentriesHandler
.handlers = com.logentries.jul.LogentriesHandler

com.logentries.jul.LogentriesHandler.token = aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
com.logentries.jul.LogentriesHandler.port = 10000
com.logentries.jul.LogentriesHandler.host = data.logentries.com
com.logentries.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("logging message goes here");
Clone this wiki locally