spring boot logback refresh

394 Views Asked by At

I know that with config server and refresh endpoint, it is possible to dynamically change the logging level in spring boot application. To get control over the log rotation policy and json encoding for file, I decided to use logback. But this will stop me from dynamically changing the logging level.

<root level="info">
    <appender-ref ref="RollingFile" />
    <appender-ref ref="Console" />
</root>

This means that only info will be written to console/file. But what if I want to change it to debug/trace during runtime?

EDIT I still dont understand the root level tag. But the logback seems to be taking the log level from application.properties, which basically answers my question.

1

There are 1 best solutions below

0
GolamMazid Sajib On

You can change loggig levle using spring-boot-acutuator endpiont.

To check loging level call this GET method endpoint:

http://host:port/contextpath/actuator/loggers

To check root level loggers call this GET method:

http://host:port/contextpath/actuator/loggers/root

To change root log level call this POST method endpoint:

http://host:port/contextpath/actuator/loggers/root

header: content-type: application-json

body:

{"configuredLevel": "TRACE"}

By calling this endpoint u can change root log level.