Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Logging ignored when using logstash-logback-encoder #453

Open
afavre opened this issue Oct 24, 2024 · 1 comment
Open

Exception Logging ignored when using logstash-logback-encoder #453

afavre opened this issue Oct 24, 2024 · 1 comment

Comments

@afavre
Copy link

afavre commented Oct 24, 2024

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?

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant