Java SDK
Official Java SDK for LogFlux with encrypted logging, resilient architecture, and production-ready features
The LogFlux Java SDK provides a secure, high-performance way to send encrypted logs to LogFlux from your Java applications, with native support for popular logging frameworks.
π View full documentation and examples on GitHub β
Installation
Maven
1
2
3
4
5
|
<dependency>
<groupId>io.logflux</groupId>
<artifactId>logflux-java-sdk</artifactId>
<version>2.0.0</version>
</dependency>
|
Gradle
1
|
implementation 'io.logflux:logflux-java-sdk:2.0.0'
|
Quick Start
Ultra-Simple Usage (2 lines!)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import io.logflux.logger.LogFlux;
public class Example {
public static void main(String[] args) {
// Initialize LogFlux (one time setup)
LogFlux.init("https://<customer-id>.ingest.<region>.logflux.io", "my-app", "lf_your_api_key", "your-secret");
// Use it with proper log levels
LogFlux.info("User login successful").join();
LogFlux.warning("Rate limit approaching").join();
LogFlux.error("Database connection failed").join();
LogFlux.close();
}
}
|
Production-Ready Setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import io.logflux.client.ResilientClient;
import io.logflux.config.ResilientClientConfig;
import java.time.Duration;
// Create resilient client with production settings
ResilientClientConfig config = new ResilientClientConfig.Builder()
.serverUrl("https://<customer-id>.ingest.<region>.logflux.io")
.node("production-server")
.apiKey("lf_your_api_key")
.secret("your-encryption-secret")
.queueSize(1000)
.flushInterval(Duration.ofSeconds(5))
.workerCount(3)
.failsafeMode(true)
.build();
try (ResilientClient client = new ResilientClient(config)) {
// Send logs - they're queued and sent asynchronously
client.info("Application started successfully").join();
client.error("Database connection failed").join();
// Flush ensures all logs are sent before shutdown
client.flush(Duration.ofSeconds(10)).join();
}
|
Key Features
- Strong Encryption: AES-256-GCM encryption via RSA handshake
- Syslog Log Levels: Full support for Emergency through Debug levels
- Ultra-Simple API: Get started with just 2 lines of code
- Resilient Architecture: In-memory queuing, automatic retries, failsafe mode
- Built-in Statistics: Monitor performance with detailed metrics
- Logger Adapters: Drop-in replacements for SLF4J, Log4j2, and JUL
Configuration
Environment Variables
1
2
3
4
5
6
7
8
9
|
# Required
export LOGFLUX_API_KEY="lf_your_api_key"
export LOGFLUX_SERVER_URL="https://<customer-id>.ingest.<region>.logflux.io"
# Optional
export LOGFLUX_QUEUE_SIZE="1000"
export LOGFLUX_FLUSH_INTERVAL="5" # seconds
export LOGFLUX_WORKER_COUNT="2"
export LOGFLUX_FAILSAFE_MODE="true"
|
From Environment
1
2
|
// Create client from environment variables
ResilientClient client = ResilientClient.createFromEnv("my-app", "your-secret");
|
Logger Adapters
SLF4J Integration
1
2
3
4
5
6
7
8
9
10
|
import io.logflux.adapters.Slf4jAdapter;
import io.logflux.client.ResilientClient;
// Configure LogFlux as SLF4J backend
ResilientClient client = ResilientClient.createFromEnv("my-app", "secret");
Slf4jAdapter.configureAsDefault(client);
// Use existing SLF4J code - now goes to LogFlux
Logger logger = LoggerFactory.getLogger(MyClass.class);
logger.info("Message");
|
Spring Boot Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
@RestController
public class UserController {
private final ResilientClient logFlux;
public UserController() {
this.logFlux = ResilientClient.createFromEnv("api", "secret");
}
@PostMapping("/login")
public ResponseEntity<String> login(@RequestBody LoginRequest request) {
logFlux.info(String.format(
"{\"event\": \"login\", \"user\": \"%s\"}",
request.getUserId()
));
return ResponseEntity.ok("Success");
}
}
|
Log Levels
Level |
Value |
Method |
Description |
Emergency |
1 |
.emergency() |
System is unusable |
Alert |
2 |
.alert() |
Immediate action needed |
Critical |
3 |
.critical() |
Critical conditions |
Error |
4 |
.error() |
Error conditions |
Warning |
5 |
.warning() |
Warning conditions |
Notice |
6 |
.notice() |
Normal but significant |
Info |
7 |
.info() |
Informational messages |
Debug |
8 |
.debug() |
Debug-level messages |
Requirements
- Java: 11 or later
- Dependencies: Jackson (JSON), OkHttp (HTTP client)
- Optional: SLF4J, Log4j2, Logback (for adapters)
Support