kotlin-logging icon indicating copy to clipboard operation
kotlin-logging copied to clipboard

Exception Logging ignored when using logstash-logback-encoder

Open afavre opened this issue 1 year ago • 3 comments

Hello, I upgraded from the previous version of the project io.github.microutils and noticed that I could not make work Exception logging work when using logstash-logback-encoder (version 7.0.4).

I tried with a small Micronaut Project with Kotlin adding these 2 dependencies:

    implementation("io.github.oshai:kotlin-logging-jvm:7.0.0")
    implementation("net.logstash.logback:logstash-logback-encoder:7.4")

Logback Config:

<configuration>
    <appender name="JSON_CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LogstashEncoder" />
    </appender>

    <root level="INFO">
        <appender-ref ref="JSON_CONSOLE" />
    </root>
</configuration>

Controller

package example.micronaut
import io.github.oshai.kotlinlogging.KotlinLogging
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get

val log = KotlinLogging.logger {}

@Controller
open class HomeController() {

    @Get
    fun index(): Map<String, String> {
        try {
            throw Exception("Issue with my code")
        } catch (e: Exception) {
            log.error(e) { "Error with stacktrace" }
            log.error { "Error without stacktrace" }
        }
        log.info { "Back to the main code" }
        return mapOf("message" to "Hello World")
    }
}

Output:

{"message":"Error without stacktrace","logger_name":"example.micronaut.HomeController","level":"ERROR"}
{"message":"Back to the main code","logger_name":"example.micronaut.HomeController","level":"INFO"}

It works fine is using the default ch.qos.logback.core.ConsoleAppender.

Am I doing something wrong?

afavre avatar Oct 24 '24 07:10 afavre

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

github-actions[bot] avatar Oct 24 '24 07:10 github-actions[bot]

Doesn’t seems like the issue is related to that lib.

oshai avatar Dec 03 '24 18:12 oshai

+1

ssouza avatar Dec 18 '24 18:12 ssouza