Quick Start¶
Get up and running with Hermes in just a few minutes.
Installation¶
Add the following dependencies to your pom.xml:
<dependencies>
<!-- Core API -->
<dependency>
<groupId>io.github.dotbrains</groupId>
<artifactId>hermes-api</artifactId>
<version>1.0.0</version>
</dependency>
<!-- Annotation processor (for @InjectLogger) -->
<dependency>
<groupId>io.github.dotbrains</groupId>
<artifactId>hermes-processor</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<!-- Core implementation -->
<dependency>
<groupId>io.github.dotbrains</groupId>
<artifactId>hermes-core</artifactId>
<version>1.0.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.github.dotbrains</groupId>
<artifactId>hermes-processor</artifactId>
<version>1.0.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Your First Logger¶
Using @InjectLogger (Recommended)¶
The easiest way to use Hermes is with the @InjectLogger annotation:
import io.github.dotbrains.InjectLogger;
@InjectLogger
public class UserService extends UserServiceHermesLogger {
public void createUser(String username) {
log.info("Creating user: {}", username);
try {
saveToDatabase(username);
log.info("User {} created successfully", username);
} catch (Exception e) {
log.error("Failed to create user: {}", username, e);
}
}
}
How it works
The annotation processor generates a base class UserServiceHermesLogger with a protected Logger log field. Your class simply extends it and uses log directly.
Manual Logger Creation¶
If you prefer not to use annotation processing:
import io.github.dotbrains.Logger;
import io.github.dotbrains.LoggerFactory;
public class UserService {
private static final Logger log = LoggerFactory.getLogger(UserService.class);
public void createUser(String username) {
log.info("Creating user: {}", username);
}
}
Log Levels¶
Hermes supports five log levels (from least to most severe):
log.trace("Detailed debug information");
log.debug("Debug information");
log.info("Informational messages");
log.warn("Warning messages");
log.error("Error messages");
Parameterized Logging¶
Use {} placeholders for efficient parameterized logging:
// Single parameter
log.info("User {} logged in", username);
// Multiple parameters
log.debug("Processing order {} for user {} with total {}", orderId, username, total);
// With exception (always last parameter)
log.error("Failed to process order {}", orderId, exception);
Performance
Parameterized logging avoids string concatenation, which is more efficient and only executed if the log level is enabled.
Next Steps¶
- Learn about Logger Injection in detail
- Explore MDC for contextual logging
- Configure Async Logging for high-performance applications
- Set up Spring Boot Integration