Skip to content

Commit d7b8103

Browse files
committed
Added ConsoleCaptor example for log4j-slf4j18
1 parent 5b3be81 commit d7b8103

File tree

10 files changed

+106
-46
lines changed

10 files changed

+106
-46
lines changed

Diff for: README.MD

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ A repository containing different java tutorials
1313
- [Unit Testing Static Methods with Mockito](mock-statics-with-mockito)
1414
- [Unit Testing Java Util Logging logs with LogCaptor](log-captor-examples/log-captor-with-java-util-logging)
1515
- [Unit Testing Log4J logs with LogCaptor](log-captor-examples/log-captor-with-log4j-core)
16-
- [Unit testing Log4J logs with LogCaptor while using log4j-slf4j18-impl](log-captor-examples/log-captor-with-log4j-slf4j18)
1716
- [Unit Testing SLF4J Logback logs with LogCaptor](log-captor-examples/log-captor-with-slf4j-logback-classic)
1817
- [Unit Testing SLF4J Log4j logs with LogCaptor](log-captor-examples/log-captor-with-slf4j-log4j)
1918
- [Unit Testing Spring Boot Log4j2 logs with LogCaptor](log-captor-examples/log-captor-with-spring-boot-starter-log4j2)
19+
- [Unit testing logs with ConsoleCaptor while using log4j-slf4j18-impl](console-captor-examples/console-captor-with-log4j-slf4j18)
2020

2121
## Security 🔐
2222
- [Instant Server SSL Reloading with Spring Boot and Jetty](instant-server-ssl-reloading)

Diff for: log-captor-examples/log-captor-with-log4j-slf4j18/pom.xml renamed to console-captor-examples/console-captor-with-log4j-slf4j18/pom.xml

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<parent>
8-
<artifactId>log-captor-examples-parent</artifactId>
8+
<artifactId>console-captor-examples-parent</artifactId>
99
<groupId>io.github.hakky54</groupId>
1010
<version>1.0.0-SNAPSHOT</version>
1111
</parent>
1212

13-
<artifactId>log-captor-with-log4j-slf4j18</artifactId>
13+
<artifactId>console-captor-with-log4j-slf4j18</artifactId>
1414
<version>1.0.0-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616

@@ -19,13 +19,8 @@
1919
<groupId>org.apache.logging.log4j</groupId>
2020
<artifactId>log4j-slf4j18-impl</artifactId>
2121
<version>${version.log4j-log4j-slf4j18}</version>
22-
<exclusions>
23-
<exclusion>
24-
<groupId>org.slf4j</groupId>
25-
<artifactId>slf4j-api</artifactId>
26-
</exclusion>
27-
</exclusions>
2822
</dependency>
2923
</dependencies>
3024

25+
3126
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package nl.altindag.console.log4j;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
public class FooService {
7+
8+
private static final Logger LOGGER = LoggerFactory.getLogger(FooService.class);
9+
10+
public void hello() {
11+
LOGGER.info("Hello there friend!");
12+
}
13+
14+
public static void main(String[] args) {
15+
new FooService().hello();
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package nl.altindag.console.log4j;
2+
3+
import nl.altindag.console.ConsoleCaptor;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
class FooServiceShould {
9+
10+
@Test
11+
void sayHello() {
12+
ConsoleCaptor consoleCaptor = new ConsoleCaptor();
13+
14+
FooService fooService = new FooService();
15+
fooService.hello();
16+
17+
assertThat(consoleCaptor.getStandardOutput()).hasSize(1);
18+
assertThat(consoleCaptor.getStandardOutput().get(0)).contains("Hello there friend!");
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="INFO">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="debug">
10+
<AppenderRef ref="Console" />
11+
</Root>
12+
</Loggers>
13+
</Configuration>

Diff for: console-captor-examples/pom.xml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<modules>
8+
<module>console-captor-with-log4j-slf4j18</module>
9+
</modules>
10+
11+
<parent>
12+
<artifactId>java-tutorials</artifactId>
13+
<groupId>io.github.hakky54</groupId>
14+
<version>1.0.0-SNAPSHOT</version>
15+
</parent>
16+
17+
<artifactId>console-captor-examples-parent</artifactId>
18+
<version>1.0.0-SNAPSHOT</version>
19+
<packaging>pom</packaging>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>io.github.hakky54</groupId>
24+
<artifactId>consolecaptor</artifactId>
25+
<version>${version.consolecaptor}</version>
26+
<scope>test</scope>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>org.junit.jupiter</groupId>
31+
<artifactId>junit-jupiter-api</artifactId>
32+
<version>${version.junit}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter-engine</artifactId>
38+
<version>${version.junit}</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.assertj</groupId>
43+
<artifactId>assertj-core</artifactId>
44+
<version>${version.assertj-core}</version>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
</project>

Diff for: log-captor-examples/log-captor-with-log4j-slf4j18/src/main/java/nl/altindag/log4j/FooService.java

-14
This file was deleted.

Diff for: log-captor-examples/log-captor-with-log4j-slf4j18/src/test/java/nl/altindag/log4j/FooServiceShould.java

-22
This file was deleted.

Diff for: log-captor-examples/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<module>log-captor-with-slf4j-logback-classic</module>
1010
<module>log-captor-with-slf4j-log4j</module>
1111
<module>log-captor-with-spring-boot-starter-log4j2</module>
12-
<module>log-captor-with-log4j-slf4j18</module>
1312
</modules>
1413

1514
<parent>

Diff for: pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<module>spring-cn-validation-with-aop</module>
2020
<module>instant-server-ssl-reloading-with-vertx</module>
2121
<module>instant-server-ssl-reloading-with-netty</module>
22+
<module>console-captor-examples</module>
2223
</modules>
2324

2425
<licenses>

0 commit comments

Comments
 (0)