R
R
Romanov19812020-10-18 18:48:36
Java
Romanov1981, 2020-10-18 18:48:36

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>


Then I do the following properties:
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


Next, I make one controller.

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";

    }


and launch.

And here is the question:

The entire Internet, as one, speaks only about one thing and shows about one thing: if you need to display a message in some place with a certain info, debug, trace, error, warn mark, then it will be displayed. To avoid using System.out.println(); , this same debugger is used. That's all I understood. and I have not seen more.

And the question itself: why were only three messages info, error, warn displayed?

https://github.com/romanych2021/TestDebuger

PS If you think it's a stupid question, please don't scold me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2020-10-18
@Romanov1981

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 question

Ask a Question

731 491 924 answers to any question