1.

Explain how you go about logging configuration in Spring Boot.

Answer»

You can use logging with SPRING Boot by specifying log levels on application.properties file.

Spring Boot, by default, incorporates spring-boot-STARTER-logging as a transitive reliance for the spring-boot-starter MODULE. By default, Spring Boot incorporates SLF4J with Logback usage.

Presently, if Logback is accessible, Spring Boot will pick it as the logging handler. You can undoubtedly arrange logging levels inside the application.properties document without making logging SUPPLIER explicit setup files, for example, logback.xml or log4j.properties.

For example, the configuration is : 

logging.level.org.hibernate=ERROR

logging.level.org.springframework.web=INFO

If you would like to include Log4J or Log4j2, instead of Logback, you can exclude spring-boot-starter-logging and include the respective logging starter, as follows:

<dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter</artifactId>     <exclusions>         <exclusion>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-logging</artifactId>         </exclusion>     </exclusions> </dependency> <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-log4j</artifactId> </dependency>

You will need to add log4j.properties file to the root classpath, Spring Boot will automatically pick it up.

With log configuration, you may see the following THINGS:

  • Source Class name
  • Thread Name /ID
  • Date & Time
  • Log Level ( Debug/Trace/Info/Warn/Error)
  • Actual Log Message


Discussion

No Comment Found