Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot turn off logging for a package

I prefer to throw my own exceptions for business logic. For example I have a class com.mine.exception.DuplicateClientException. Is there some configuration where I can turn off printing the stack trace for package com.mine.exception ?

Something like:

logging.level.com.mine.exception=OFF
like image 237
Frank Avatar asked Aug 11 '17 11:08

Frank


People also ask

How do I turn off Info logs in slf4j?

To disable this behavior, you must add a logback configuration file called logback. xml in your java classpath root. You can download this minimal logback. xml file and add it in the src/main/resources directory for a maven project or beside fr directory for a simple java project.

How do I enable debug logs in spring boot?

You can enable debug logging by specifying --debug when starting the application from the command-line. Spring Boot provides also a nice starting point for logback to configure some defaults, coloring etc. the base. xml file which you can simply include in your logback.


1 Answers

In application.properties you can add ‘logging.level.*=LEVEL’ where ‘LEVEL’ is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF. * is responsible for package/class.

For example

logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

This means that root logger has WARN level. org.springframework.web is on DEBUG level, but all hibernates files are logged only ERROR.

like image 173
Siddhesh Avatar answered Oct 06 '22 20:10

Siddhesh