A low-impact, highly performant structured meta-logging library for Java.
Metalog is a modern logging framework designed for high-performance Java applications. It eliminates unnecessary overhead by generating log messages only when they are consumed, and supports both synchronous and asynchronous processing patterns with fine-grained control over message routing and ordering.
Current release: 1.2.3
// Minimal logging - message generated only if consumed
publish(() -> "Hello World");
// Include exception, thread info, and timestamp
publish(() -> {
StringBuilder builder = new StringBuilder();
builder.append(e.getMessage());
builder.append(System.lineSeparator());
builder.append(someCostlyOperation());
return builder;
},
b -> b // Meta builder callback
.thrown(e) // retain exception
.thread() // retain current thread information
.time()); // retain current time
// Clean method reference for complex message generation
publish(this::someMethodToProduceTheMessage);
Add Metalog to your project via Maven Central:
<dependency>
<groupId>io.github.jonloucks.metalog</groupId>
<artifactId>metalog</artifactId>
<version>1.2.3</version>
</dependency>
Or Gradle:
implementation 'io.github.jonloucks.metalog:metalog:1.2.3'
The Publisher interface is responsible for publishing log messages. Use GlobalMetalog for convenient global access or create dedicated Metalog instances.
Implement Subscriber to consume log messages. Subscribers receive both the log message and associated metadata.
Metadata attached to each log message includes:
Channels categorize log messages for routing. Common channels include:
info - General information messagesdebug - Debugging informationwarn - Warning messageserror - Error messagestrace - Detailed trace informationMetalog supports extensive configuration through Metalog.Config:
Metalog metalog = GlobalMetalog.createMetalog(builder -> builder
.unkeyedThreadCount(20) // Worker threads for unkeyed messages
.keyedQueueLimit(1000) // Queue limit for keyed messages
.unkeyedFairness(false) // FIFO processing for unkeyed messages
.shutdownTimeout(Duration.ofSeconds(60)) // Graceful shutdown timeout
);
Metalog follows a clean separation between API and implementation:
The library uses dependency injection through the Contracts API for flexible component replacement and testing.
Metalog uses Gradle for building:
# Build and run all tests
./gradlew build
# Run tests with coverage
./gradlew test jacocoTestReport
# Publish to local Maven repository
./gradlew publishToMavenLocal
# Generate Javadoc
./gradlew javadoc
Contributions are welcome! Please see:
For security concerns, please see SECURITY.md.
See LICENSE file for details.
Release notes are available in the notes/ directory: