Skip to content

Commit 7ef8ae7

Browse files
committed
Removed kotling logger lib. Migrated to spring-starter-logging
1 parent 3eaaa62 commit 7ef8ae7

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ version = "1.0.0"
3636
dependencies {
3737
implementation("org.jetbrains.kotlin:kotlin-reflect")
3838
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
39-
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3")
40-
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3")
39+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.0")
40+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.0")
4141

42-
implementation("org.apache.logging.log4j:log4j-api-kotlin:1.2.0")
42+
implementation("org.springframework.boot:spring-boot-starter-logging:2.7.2")
4343

4444
testImplementation("org.junit.jupiter:junit-jupiter:5.9.0")
4545
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")

src/main/kotlin/com/softwareplace/json/logger/log/JsonLogger.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ package com.softwareplace.json.logger.log
33
import com.fasterxml.jackson.databind.ObjectMapper
44
import com.softwareplace.json.logger.mapper.getObjectMapper
55
import org.apache.logging.log4j.Level
6-
import org.apache.logging.log4j.kotlin.KotlinLogger
7-
import org.apache.logging.log4j.kotlin.logger
6+
import org.slf4j.Logger
7+
import org.slf4j.LoggerFactory
88

9-
val Any.kLogger
10-
get() = logger(javaClass.name)
119

10+
inline fun <reified T : Any> T.logger() = LoggerFactory.getLogger(T::class.java)
1211

1312
private data class LoggerModel(
1413
val message: String?,
1514
val properties: Map<String, Any>?,
1615
val errorMessage: String? = null,
1716
)
1817

19-
data class JsonLog(private val logger: KotlinLogger) {
18+
data class JsonLog(private val logger: Logger) {
2019
private var message: String? = null
2120
private var properties: HashMap<String, Any>? = null
2221
private var error: Throwable? = null
@@ -61,7 +60,7 @@ data class JsonLog(private val logger: KotlinLogger) {
6160
}
6261

6362

64-
fun KotlinLogger.run(
63+
fun Logger.run(
6564
level: Level = Level.INFO,
6665
message: String,
6766
error: Throwable? = null

src/test/kotlin/com/softwareplace/json/logger/log/JsonLogTest.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import io.mockk.verify
66
import org.apache.logging.log4j.Level
77
import org.junit.jupiter.api.Test
88
import org.junit.jupiter.api.extension.ExtendWith
9+
import org.slf4j.Logger
10+
import org.slf4j.LoggerFactory
11+
import org.slf4j.spi.LoggerFactoryBinder
912
import java.time.LocalDate
13+
import com.softwareplace.json.logger.log.*
1014

1115
@Suppress("KotlinPlaceholderCountMatchesArgumentCount")
1216
@ExtendWith(MockKExtension::class)
1317
class JsonLogTest {
14-
1518
@Test
1619
fun `must to call logger with expected json`() {
17-
val logger = spyk(kLogger)
20+
val logger = spyk(logger())
1821
JsonLog(logger)
1922
.add("test-key", "test-value")
2023
.run(Level.INFO)
@@ -27,7 +30,7 @@ class JsonLogTest {
2730

2831
@Test
2932
fun `must to call log debug with expected json`() {
30-
val logger = spyk(kLogger)
33+
val logger = spyk(logger())
3134
JsonLog(logger)
3235
.add("test-key", "test-value")
3336
.run(Level.DEBUG)
@@ -40,7 +43,7 @@ class JsonLogTest {
4043

4144
@Test
4245
fun `must to call log warn with expected json`() {
43-
val logger = spyk(kLogger)
46+
val logger = spyk(logger())
4447
JsonLog(logger)
4548
.add("test-key", "test-value")
4649
.run(Level.WARN)
@@ -53,7 +56,7 @@ class JsonLogTest {
5356

5457
@Test
5558
fun `must to call logger with error message`() {
56-
val logger = spyk(kLogger)
59+
val logger = spyk(logger())
5760
val error = IllegalArgumentException("test error log message")
5861
JsonLog(logger)
5962
.add("test-key", "test-value")
@@ -68,7 +71,7 @@ class JsonLogTest {
6871

6972
@Test
7073
fun `must to call logInfo with message`() {
71-
val logger = spyk(kLogger)
74+
val logger = spyk(logger())
7275
JsonLog(logger)
7376
.add("test-key", "test-value")
7477
.message("this is a test log message created in {} of lib version {}", LocalDate.of(2022, 8, 12), "1.0.0")
@@ -88,7 +91,7 @@ class JsonLogTest {
8891

8992
@Test
9093
fun `must to call log error with message`() {
91-
val logger = spyk(kLogger)
94+
val logger = spyk(logger())
9295
val error = IllegalArgumentException("test error log message")
9396
JsonLog(logger)
9497
.add("test-key", "test-value")

0 commit comments

Comments
 (0)