diff options
author | Mavlushechka <mavlushechka@gmail.com> | 2022-09-27 21:51:53 +0500 |
---|---|---|
committer | Mavlushechka <mavlushechka@gmail.com> | 2022-09-27 21:51:53 +0500 |
commit | c0469440d567349cdf20d6296b9949e05348d1f4 (patch) | |
tree | 733fc3d58647f12db7bd34a786edfcb37595f46d /src/main/java/com/mavlushechka/a1qa/utils/LoggerUtils.java | |
parent | e7c380c64056a004a1d61f04df7afb2a1c1c3675 (diff) | |
parent | 441d7a21494f3cb9a16ae6095540326938af536b (diff) |
Merge branch 'testing-framework' into task-3
Diffstat (limited to 'src/main/java/com/mavlushechka/a1qa/utils/LoggerUtils.java')
-rw-r--r-- | src/main/java/com/mavlushechka/a1qa/utils/LoggerUtils.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/utils/LoggerUtils.java b/src/main/java/com/mavlushechka/a1qa/utils/LoggerUtils.java new file mode 100644 index 0000000..51d49ae --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/utils/LoggerUtils.java @@ -0,0 +1,46 @@ +package com.mavlushechka.a1qa.utils; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.config.ConfigurationSource; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.core.config.xml.XmlConfiguration; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class LoggerUtils { + + private final static File CONFIGURATION_FILE = new File("src/main/resources/log4j2.xml"); + private static Logger logger; + private static int step = 0; + + + private LoggerUtils() { + } + + public static void initialize() { + try { + Configurator.initialize(new XmlConfiguration(null, new ConfigurationSource(new FileInputStream(CONFIGURATION_FILE)))); + } catch (IOException ioException) { + throw new RuntimeException(ioException); + } + logger = LogManager.getLogger(); + } + + public static void info(String text) { + logger.log(Level.INFO, text); + } + + public static void error(String text) { + logger.log(Level.ERROR, text); + } + + public static void step(String text) { + step++; + logger.log(Level.INFO, "Step %d: %s".formatted(step, text)); + } + +} |