Skip to content

Commit 6d3ee48

Browse files
Update CLAUDE.md to document kotlin-logging migration
- Add kotlin-logging-jvm 7.0.3 to dependency list - Update Logging section with kotlin-logging patterns and syntax - Document lambda-based lazy evaluation benefits - Add migration status note (January 2026) - Provide both new kotlin-logging and legacy SLF4J examples - Update Migration Notes section Co-authored-by: bedaHovorka <bedaHovorka@users.noreply.github.com>
1 parent 1efd92e commit 6d3ee48

1 file changed

Lines changed: 37 additions & 14 deletions

File tree

CLAUDE.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This project uses Gradle with Kotlin DSL for building. Java 21 LTS is the minimu
3232
- Refactored deprecated Observable/Observer to PropertyChangeSupport
3333
- Extracted jDisco library to separate repository in January 2026
3434
- **Migrated from Java to Kotlin in January 2026** - See "Kotlin Migration History" section below
35+
- **Migrated from SLF4J to kotlin-logging in January 2026** - Eliminates verbose guard checks with lambda-based lazy evaluation
3536

3637
### Dependency Management
3738

@@ -44,7 +45,8 @@ Dependencies are managed via Gradle with fallback strategy:
4445
- **JUnit 5.11.4** - Testing framework (JUnit Jupiter API and Engine)
4546
- **AssertJ 3.27.6** - Fluent assertion library for better test readability
4647
- **Mockito 5.21.0** - Mocking framework
47-
- **SLF4J 2.0.17** + **Logback 1.5.23** - Logging framework
48+
- **kotlin-logging-jvm 7.0.3** - Kotlin logging wrapper (lambda-based lazy evaluation)
49+
- **SLF4J 2.0.17** + **Logback 1.5.23** - Logging backend (used by kotlin-logging)
4850

4951
Gradle automatically downloads dependencies during the build. Configuration files:
5052
- `build.gradle.kts` - Build configuration and dependency declarations
@@ -777,7 +779,9 @@ Output goes to `doc/` directory.
777779

778780
## Logging
779781

780-
The application uses SLF4J with Logback for logging. This provides flexible log configuration and runtime control.
782+
The application uses **kotlin-logging** (a Kotlin wrapper for SLF4J) with Logback as the backend. This provides flexible log configuration, runtime control, and lambda-based lazy evaluation to eliminate verbose guard checks.
783+
784+
**Migration Status (January 2026):** Migrated from SLF4J to kotlin-logging. All logger declarations now use `KotlinLogging.logger {}` for automatic lazy evaluation and cleaner syntax.
781785

782786
### Configuration Files
783787

@@ -786,7 +790,7 @@ The application uses SLF4J with Logback for logging. This provides flexible log
786790

787791
### Log Levels
788792

789-
Standard SLF4J log levels (most to least verbose):
793+
Standard log levels (most to least verbose):
790794
- `TRACE` - Very detailed diagnostic information
791795
- `DEBUG` - Detailed debugging information
792796
- `INFO` - General informational messages (default for most loggers)
@@ -842,20 +846,39 @@ The following loggers are configured in `logback.xml`:
842846

843847
### Adding Logging to Code
844848

845-
When modifying Java source code (following the conservative approach), use SLF4J logging:
849+
When adding logging to Kotlin code, use kotlin-logging for automatic lazy evaluation:
846850

847-
```java
848-
import org.slf4j.Logger;
849-
import org.slf4j.LoggerFactory;
851+
```kotlin
852+
import io.github.oshai.kotlinlogging.KotlinLogging
853+
854+
private val logger = KotlinLogging.logger {}
855+
856+
// In methods - lambda-based lazy evaluation (no manual guard checks needed):
857+
logger.trace { "Very detailed trace message" }
858+
logger.debug { "Debug message with context: $variable" }
859+
logger.info { "Informational message" }
860+
logger.warn { "Warning message" }
861+
logger.error(exception) { "Error message" }
862+
```
850863

851-
private static final Logger logger = LoggerFactory.getLogger(ClassName.class);
864+
**Benefits of kotlin-logging:**
865+
- **No manual guard checks** - Eliminates verbose `if (logger.isDebugEnabled)` patterns
866+
- **Lazy evaluation** - Lambda content only evaluated if log level is enabled
867+
- **String interpolation** - Use Kotlin string templates (`$variable`) instead of SLF4J placeholders
868+
- **Cleaner syntax** - Idiomatic Kotlin logger initialization
852869

853-
// In methods:
854-
logger.trace("Very detailed trace message");
855-
logger.debug("Debug message with context: {}", variable);
856-
logger.info("Informational message");
857-
logger.warn("Warning message");
858-
logger.error("Error message", exception);
870+
**Legacy SLF4J syntax (deprecated, use only for compatibility):**
871+
872+
```kotlin
873+
import org.slf4j.Logger
874+
import org.slf4j.LoggerFactory
875+
876+
private val logger: Logger = LoggerFactory.getLogger(ClassName::class.java)
877+
878+
// Old pattern with manual guard checks (avoid in new code):
879+
if (logger.isDebugEnabled) {
880+
logger.debug("Debug message with context: {}", variable)
881+
}
859882
```
860883

861884
## Known Bugs and Issues

0 commit comments

Comments
 (0)