How to change logging level with the MVC endpoint – new Actuator Loggers Endpoint | Spring Boot

Spring Boot 1.5.1 provides some new features. Among them, we have a new actuator loggers endpoint, which helps us to view and change logging level of application with the MVC endpoint.

This tutorial shows you the way to do this with http GET/POST request.

I. Technology

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.1.RELEASE

II. Overview
1. Dependency

A Spring Boot Starter Dependency for Actuator should be present in pom.xml:

2. Loggers Endpoint

Actuator endpoints help us to monitor and interact with our application. Spring Boot includes a number of built-in endpoints including Loggers Endpoint. It shows current active level for logger and how we config. In JSON format:


3. Customize endpoint

We can change how this endpoint exposes by add some code to, in this example:

management.port is used to change the HTTP port.
– Because the management port is often protected by a firewall, so we need to disable management security like this:
management.address= indicates that we only allow to access by this IP address, in this case, it is localhost.
management.context-path can be used to set a prefix for management endpoint.
endpoints.loggers.enabled (true/false) is to enable/disable endpoint by name, in the example, we enable loggers endpoint.

So the url to be called should be: http://localhost:8081/actuator/loggers/[package]

4. View Logging Level

Just make a HTTP GET request to /loggers/[our qualified name of package]. The JSON String result will be:

5. Change Logging Level

We can issue a HTTP POST request to /loggers/[our qualified name of package] with the following JSON:

III. Practice
1. Add dependencies

Open pom.xml, add those dependencies:

2. Add configuration for Endpoint

Open and add:

3. Create LogInfo class

Under package com.javasampleapproach.loggerendpoint, create package logger and add LogInfo class, this POJO class is used for creating correlative JsonString.

4. Create code for testing

In your main class which is annotated by @SpringBootApplication, use the code below:

5. Check results

– Config maven build:
clean install
– Run project with mode Spring Boot App
– Check results in Console Window:

IV. Source Code


By grokonez | February 16, 2017.

Last updated on June 4, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *