Skip to content

Commit

Permalink
Fix spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmanil committed Nov 29, 2024
1 parent 16ddfef commit 99c4969
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import java.io.StringWriter
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.Appender
import org.apache.logging.log4j.core.appender.WriterAppender
import org.apache.logging.log4j.core.config.json.JsonConfiguration
import org.apache.logging.log4j.core.layout.JsonLayout
import org.apache.logging.log4j.core.layout.PatternLayout

fun newPatternLayout(pattern: String): PatternLayout =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.OutputStreamAppender
import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLogging
import java.io.ByteArrayOutputStream
import net.logstash.logback.argument.StructuredArguments
import net.logstash.logback.composite.JsonProviders
import net.logstash.logback.composite.loggingevent.ArgumentsJsonProvider
import net.logstash.logback.composite.loggingevent.LoggingEventPatternJsonProvider
import net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder
import java.io.ByteArrayOutputStream
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeAll
Expand Down Expand Up @@ -105,53 +104,38 @@ class LogbackLoggerWrapperTest {
logger.info { "simple logback info message" }
warnLogger.warn { "simple logback warn message" }
errorLogger.error { "simple logback error message" }
val lines =
logOutputStream
.toByteArray()
.toString(Charsets.UTF_8)
.trim()
.lines()
val jsonLines = jsonLogOutputStream
.toByteArray()
.toString(Charsets.UTF_8)
.trim()
.lines()
val lines = logOutputStream.toByteArray().toString(Charsets.UTF_8).trim().lines()
val jsonLines = jsonLogOutputStream.toByteArray().toString(Charsets.UTF_8).trim().lines()
assertEquals(
"INFO io.github.oshai.kotlinlogging.logback.internal.LogbackLoggerWrapperTest - simple logback info message",
lines[0],
)
assertEquals(
"""{"message":"simple logback info message"}""",
jsonLines[0]
)
assertEquals("""{"message":"simple logback info message"}""", jsonLines[0])
assertEquals("WARN warnLogger - simple logback warn message", lines[1])
assertEquals("""{"message":"simple logback warn message"}""", jsonLines[1])
assertEquals("ERROR errorLogger - simple logback error message", lines[2])
assertEquals("""{"message":"simple logback error message"}""",jsonLines[2])
assertEquals("""{"message":"simple logback error message"}""", jsonLines[2])
}

@Test
fun testLogbackLoggerWithArguments() {
logger.atInfo {
message = "msg"
arguments = arrayOf(StructuredArguments.keyValue("arg1", "val1"), StructuredArguments.keyValue("arg2", "val2"))
arguments =
arrayOf(
StructuredArguments.keyValue("arg1", "val1"),
StructuredArguments.keyValue("arg2", "val2"),
)
}
val lines =
logOutputStream
.toByteArray()
.toString(Charsets.UTF_8)
.trim()
.lines()
val jsonLines = jsonLogOutputStream
.toByteArray()
.toString(Charsets.UTF_8)
.trim()
.lines()
val lines = logOutputStream.toByteArray().toString(Charsets.UTF_8).trim().lines()
val jsonLines = jsonLogOutputStream.toByteArray().toString(Charsets.UTF_8).trim().lines()

assertEquals(1, lines.size)
assertEquals(1, jsonLines.size)
assertEquals("INFO io.github.oshai.kotlinlogging.logback.internal.LogbackLoggerWrapperTest - msg", lines[0])
assertEquals("""{"message":"msg","arg1":"val1","arg2":"val2"}""",jsonLines[0])
assertEquals(
"INFO io.github.oshai.kotlinlogging.logback.internal.LogbackLoggerWrapperTest - msg",
lines[0],
)
assertEquals("""{"message":"msg","arg1":"val1","arg2":"val2"}""", jsonLines[0])
}

}

0 comments on commit 99c4969

Please sign in to comment.