Translated :

How to make a log using Log4j, when the log method is called before it passed the "passed or failed" test

Here is a sample code and description:

log.info("Какой-то текст");// Должно быть написано при условии, что method1() сработал log.info("Какой-то текст");// Должно быть написано при условии, что method2() сработал и т.д... 

ZY For the translation, if I'm sorry, I just have 4 of the English language :)

Original:

It is passed / failed?

Here is a simple code and description:

 log.info("Some text");//Should be write to console if method1() - passed method1(); log.info("Some text");//Should be write to console if method2() - passed method2(); etc... 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Hi, maybe the following will help:

 private static Logger log = LogManager.getRootLogger(); private static String tempText; private static boolean empty = false; public static void step(String step) { if(!empty) { tempText = step; empty = true; }else{ log.info("-=============== [" + tempText + "] ===============-"); tempText = step; } } 

We make in such a way that the first method of logging does not log anything, but only stores the text in a temporary variable, and if the method passed, then it outputs step1, etc.