Reputation: 8888
I created a Spring MVC project using Spring Boot (1.5.8.RELEASE). I picked web, jpa and mysql, and added absolutely nothing in my build.gradle
.
Here is the relevant part of my application.yml
:
logging:
level: trace
That's all the configuration about logging. I just want the log messages to be shown in the console, so I just omit the logging.path
.
And I have the controller
package com.example.controllers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// other imports ...
@RestController
@RequestMapping("/")
public class DummyController {
private static final Logger LOGGER =
LoggerFactory.getLogger(DummyController.class);
@GetMapping
public void foo() {
LOGGER.info("foo");
}
}
When I send a request to /
, I get a 200 OK
response, but nothing appears in the log. Strangely, the log messages of Spring framework and Hibernate do appear in the console. Just my ad-hoc log messages missing.
Then I debugged my code, and saw that the ancestor of LOGGER
(the root of the logger tree) is a logger with log level INFO
. That's apparently not the logger I configured. However, the official documentation of Spring doesn't tell me how to get the logger instance I want. How can I do this? Is there something wrong with my code, or do I miss something in the configuration?
Upvotes: 4
Views: 13249
Reputation: 1803
IF you take a look to below link http://www.slf4j.org/api/org/apache/log4j/Level.html
TRACE level is below INFO and you are trying to log info so you are not able to see the log
logging.level.com.abc.app=DEBUG
where com.abc.app is your root dir of your application
Upvotes: 0
Reputation: 14731
The official documentation is straightforward that the root logger can be configured using logging.level.root
. But you actually can configure logging for each package/class individually
logging.level.root=TRACE # default for everything
logging.level.com.example.controllers=TRACE # for your controllers package
Similar application.yml:
logging:
level:
root: TRACE
com.example.controllers: TRACE
Upvotes: 4