sl4j Logging
Maven pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
In the maven pom.xml file, the above code shows how the dependency should be declared with an OpenJDK 14 project.
application.properties
In the spring boot application.properties file, to enable logging for debug messages, we would need to add the entry logging.level.big=DEBUG
.
Usage
1import org.slf4j.Logger;
2import org.slf4j.LoggerFactory;
3
4public class Wombat {
5
6 final Logger log = LoggerFactory.getLogger(Wombat.class);
7 Integer t;
8 Integer oldT;
9
10 public void setTemperature(Integer temperature) {
11
12 oldT = t;
13 t = temperature;
14
15 log.debug("Temperature set to {}. Old temperature was {}.", t, oldT);
16
17 if(temperature.intValue() > 50) {
18 log.info("Temperature has risen above 50 degrees.");
19 }
20 }
21}
The code block above show how log4j would typically be used in Java code.