0

I have created a SpringBoot Admin Server where clients register to it. I wish to be able to change logging levels at runtime in the 'Logging' tab in the SpringBoot Admin Server. In one of the clients, my problem is creating a parent logger for all loggers in the package "ke.co.betatech" where I would change the logging level for Logger.getLogger("ke.co.betatech") at runtime and the descendant's logging level changes. I don't want to use the root logger to change the logging level since it changes the logging levels for all loggers registered.

package ke.co.betatech.controllers;

@RestController
@RequestMapping("/api/v1")
public class Controller2 implements IController {

  Logger LOG;

  public Controller2() {
     LOG = Logger.getLogger(this.getClass());
  }

  @GetMapping("/greeting")
  public String hello() {
    LOG.info("Hello");
    return "hello"
  }
}

In the main class this is what I attempted

@SpringBootApplication
public class LoggingLevelRuntimeApplication {

   public static void main(String[] args) {
      // I created the parent logger here
      Logger log = Logger.getLogger("ke.co.betatech");
      SpringApplication.run(LoggingLevelRuntimeApplication.class, args);
   }
}

The problem is, the logger Logger.getLogger("ke.co.betatech") does not appear in the list of loggers in the Spring Boot Admin Server.

Kihats
  • 3,326
  • 5
  • 31
  • 46

2 Answers2

1

You can show the package loggers if you click on the symbol right next to the search input on the logging page.

enter image description here

joshiste
  • 2,638
  • 1
  • 14
  • 19
  • That worked. Though I noticed something; using your image above as an example, if `com.netflix` is set at a lower logging level, `com` no longer has "control" over `com.netflix`. To clarify, if `com` is at `INFO` then `com.netflix` will also be at `INFO`. If we set `com.netflix` to `DEBUG`, `com` no longer limits `com.netflix` to its logging level. – Kihats Nov 22 '16 at 04:28
  • yeah that's how things work in logback. The only thing what's missing in the ui is to switch back the configuredLevel to `null` so that parent loggers can influence the effectiveLevel again. – joshiste Nov 22 '16 at 05:24
0

Add logging.level.ke.co.betatech=DEBUG in your application.properties file and you will be able to use the logger using Logger log = Logger.getLogger("ke.co.betatech"); in any class once after SpringApplication.run() completes.

Vasu
  • 21,832
  • 11
  • 51
  • 67
  • I have done as suggested and all descendants of `Logger.getLogger("ke.co.betatech")` are set on level `DEBUG` on start up. But my problem is: 1. to be able to do this at runtime using SpringBoot Admin Server. 2. `Logger.getLogger("ke.co.betatech")` is not available in the list of loggers in SpringBoot Admin Server – Kihats Nov 21 '16 at 15:41