- Check for latest plugins from:
- https://mvnrepository.com/artifact/org.projectlombok/lombok
Search for 'slf4j' (https://mvnrepository.com/search?q=slf4j) and 'slf4j-simple' - https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
- https://mvnrepository.com/artifact/org.projectlombok/lombok
- From the latest version page, copy the maven dependencies and add them on your pom.xml file. The dependencies would be like this:
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple --><dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
- Saving your pom.xml file will download the required dependency files.
- Add 'lombok' plugin in your IDE. (Settings> Plugin> Add new> Search for 'lombok'> Install). You need to restart your IDE to complete the installation.
- Add the following in your files 'import' section:
import lombok.extern.slf4j.Slf4j;
- Add '@Slf4j' annotation just before the class.
- Print log as log.info("Your log text herer"); on any test / action methods
- In the project directory- src/main/resources, create new file named logback.xml
- Add maven dependency on pom.xml file:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
* Declareslogback-classic
, it will pull in thelogback-core
andslf4j-api
- Content of the logback.xml file is as follows:
<?xml version="1.0"?>
<configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%cyan(%d{HH:mm:ss.SSS}) %highlight(%.-5level) %yellow(%logger{50}) %highlight(%msg) %n
</pattern>
</encoder>
</appender>
<root level="info"><appender-ref ref="STDOUT" />
</root>
<logger name="Test Automation Framework logger configuration file" level="info" /></configuration>
Note: If you use logback-slf4j in your project, you may need to remove the following
dependency from your project pom.xml file.
"slf4j-simple"
Notes:
References:
References:
- https://medium.com/faun/tweaking-your-ui-automation-logs-5620b051969b
- https://mkyong.com/logging/logback-xml-example/
- https://mkyong.com/logging/slf4j-logback-tutorial/
- https://www.baeldung.com/logback
- https://javabydeveloper.com/lombok-slf4j-examples/
- https://projectlombok.org/features/log
- http://www.slf4j.org/manual.html
- https://www.javaguides.net/2019/03/project-lombok-logging-slf4j-annotation-example.html
- https://projectlombok.org/setup/intellij
- https://projectlombok.org/api/lombok/extern/slf4j/Slf4j.html
- http://www.slf4j.org/
- https://stackoverflow.com/questions/62431593/can-not-use-log-info-method-under-test-methods-while-using-slf4j/
Comments
Post a Comment