how to listener for log error messages on kotlin spring boot

Viewed 33

I've a spring boot kotlin application and I would like to intercept log messages to be able to send the error messages to a third party dashboard without needing to re-write all the logging code already existent in the project...

I've never really dealt with slf4j or other log libraries on kotlin...

The simplest way i can possible think is if somehow i could override the default log.error method then make the code i need to post the message to my dashboard and end by calling the super.error

other way would be if i somehow could listen to these messages

does anyone know how can i achieve that?

1 Answers

Assuming you are using Logback with your Spring Boot project you need to create logback-spring.xml file under src/main/resources folder and create a new appender according to your needs. As for what the appender needs to be like - can't say because you are not saying which kind of environment you need to send your logs to.

Very good intro tutorial about Spring Boot logging can be found here for example: https://www.baeldung.com/spring-boot-logging

P.S: There is nothing Kotlin specific in your problem. Just a general Spring Logging thing.

Related