Answer the question
In order to leave comments, you need to log in
Java Logger log4j?
Greetings dear forum users.
Today all day I tried to figure out how the whole "logging" thing works. I figured it out a little, but not completely, to see the official manuals are very outdated, or rather I don’t understand something, I had to watch YouTube.
In general, I do it for a test, just to see how it all works, the following dependencies in pom.xml
<!-- SLF4J LOG4J 12 Binding -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>
<!-- Apache Log4j Core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
log4j.rootLogger=info, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
public class HomeController {
Logger logger = LoggerFactory.getLogger("This my Controller");
@GetMapping(value = "/")
public String home () {
logger.info("info == Error Message");
logger.debug("debug == Error Message");
logger.trace("fatal == Error Message");
logger.error("error == Error Message");
logger.warn("warn == Error Message");
return "/home";
}
Answer the question
In order to leave comments, you need to log in
Because you have set the info
error and warn
logging level above it, and debug and trace below it.
There is a sign here:
https://javarush.ru/groups/posts/2388-logirovanie-...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question