This is very simple question, but I cannot find information.
(Maybe my knowledge about Java frameworks is severely lacking)
How can I set the logging level with application.properties?
And logging file location, etc?
This is very simple question, but I cannot find information.
(Maybe my knowledge about Java frameworks is severely lacking)
How can I set the logging level with application.properties?
And logging file location, etc?
With Springboot 2 you can set the root logging Level with an Environment Variable like this:
logging.level.root=DEBUG
Or you can set specific logging for packages like this:
logging.level.my.package.name=TRACE
According to the documentation you can have different logging levels based on java packages.
logging.level.com.mypackage.myproject=WARN
logging.level.org.springframework=DEBUG
logging.level.root=INFO
This would mean that
com.mypackage.myproject WARN logging level would be appliedorg.springframework DEBUG logging level would be appliedYou can also group together different java packages and instruct the system to use the same logging level for all packages of the group in a single line.
In the previous example you could do
logging.level.root=INFO
logging.level.org.springframework=DEBUG
logging.group.myCustomGroup = com.mypackage.myproject, com.otherpackage.otherproject, com.newpackage.newproject
logging.level.myCustomGroup=WARN
This would mean that the packages
would all have logging level WARN applied
You can try setting the log level to DEBUG it will show everything while starting the application
logging.level.root=DEBUG
Existing answers are greats. I just want to share with you a new spring boot feature allowing to group logs and set logging level on the whole group.
Exemple from the docs :
logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat
logging.level.tomcat=TRACE
It's nice feature which brings more flexibility.
We can also turn on DEBUG log via command line like below:-
java -jar <jar file> --debug
in spring boot project we can write logging.level.root=WARN but here problem is, we have to restart again even we added devtools dependency, in property file if we are modified any value will not autodetectable, for this limitation i came to know the solution i,e we can add actuator in pom.xml and pass the logger level as below shown in postman client in url bar http://localhost:8080/loggers/ROOT or http://localhost:8080/loggers/com.mycompany and in the body you can pass the json format like below
{
"configuredLevel": "WARN"
}
In my current config I have it defined in application.yaml like that:
logging:
level:
ROOT: TRACE
I am using spring-boot:2.2.0.RELEASE. You can define any package which should have the TRACE level like that.