Java — Logback / SLF4J
The com.loginformant:logback-appender Maven artifact adds a Logback appender
that batches and ships logs to LogInformant. Works with Spring Boot, plain Java 11+,
and any project that uses SLF4J as its logging facade.
1 Add the dependency
xml — Maven pom.xml
<dependency> <groupId>com.loginformant</groupId> <artifactId>logback-appender</artifactId> <version>1.0.0</version> </dependency>
groovy — Gradle build.gradle
implementation 'com.loginformant:logback-appender:1.0.0'
2 Configure in logback.xml
Add the appender to your src/main/resources/logback.xml:
xml — logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="LOGINFORMANT" class="com.loginformant.LogInformantAppender">
<apiUrl>https://app.loginformant.com</apiUrl>
<apiKey>YOUR-API-KEY-HERE</apiKey>
<!-- Optional -->
<batchSize>50</batchSize>
<flushIntervalMs>2000</flushIntervalMs>
</appender>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="LOGINFORMANT" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>
3 Log in your code (SLF4J)
java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OrderService {
private static final Logger log = LoggerFactory.getLogger(OrderService.class);
public void placeOrder(int orderId) {
log.info("Order {} placed", orderId);
try {
// your logic
} catch (Exception e) {
log.error("Failed to place order {}", orderId, e);
}
}
}
Spring Boot integration
In Spring Boot, rename the file to logback-spring.xml to support
Spring property injection:
xml — logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty name="LI_API_KEY" source="loginformant.api-key"/>
<appender name="LOGINFORMANT" class="com.loginformant.LogInformantAppender">
<apiUrl>https://app.loginformant.com</apiUrl>
<apiKey>${LI_API_KEY}</apiKey>
</appender>
<root level="INFO">
<appender-ref ref="LOGINFORMANT" />
</root>
</configuration>
Then in application.properties:
properties
loginformant.api-key=YOUR-API-KEY-HERE
In production, override the property via an environment variable:
LOGINFORMANT_API_KEY=your-key with the Spring
spring.config.import=optional:file:.env[.properties] pattern, or via
your deployment platform's secrets manager.
MDC (Structured Context)
Use SLF4J's MDC to attach key-value context to every log event.
All MDC values are forwarded to LogInformant as properties:
java
import org.slf4j.MDC;
public void processPayment(String userId, String requestId) {
MDC.put("userId", userId);
MDC.put("requestId", requestId);
try {
log.info("Processing payment");
// your logic
} finally {
MDC.clear(); // always clear in a finally block
}
}
Log level mapping
| Logback | LogInformant |
|---|---|
| TRACE | Debug |
| DEBUG | Debug |
| INFO | Information |
| WARN | Warning |
| ERROR | Error |