How to work with Log in Java? [closed]

2

I need to make a condition based on the Log of my Java project.

Ex:

Enquanto(TextoDoLog == "PalavraTal"){
    faça algo;
}

But I do not know if I have to create some class, or method, how to handle it.

    
asked by anonymous 25.07.2017 / 17:47

1 answer

1

Java has logging frameworks , Log4j the most famous of them.

As with any framework, a previous configuration is necessary so that you can use it, but in the case of Log4j it is very simple.

Once configured, you can "log" your application only with method calls like the following:

  • logger.error("Ocorreu um erro aqui");

  • logger.warn("Atenção!");

  • logger.info("Informação :P");

Among others ...

With Log4j you can configure how the log will be stored: whether it will only be displayed on the server console, whether it will save a separate file and so on.

In addition, you can format how the log is stored, including the level (error, info, warn, debug and etc), date, time, the class / strong> where the log was created.

Here has a tutorial how to configure and use Log4j.

    
25.07.2017 / 21:22