Skip to content

Commit bdb42b7

Browse files
committed
Log4j pattern experiments
1 parent 97652bc commit bdb42b7

13 files changed

Lines changed: 420 additions & 2 deletions

File tree

benchmark/key-value-db-benchmark/README.md

100755100644
File mode changed.

corejava-exp/corejava-io-exp/src/test/java/cz/znj/kvr/sw/exp/java/corejava/io/bytes/InputStreamSizeTest.java

100755100644
File mode changed.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Log4j2 pattern experiments
2+
3+
```shell
4+
# standard pattern with exception:
5+
java -Dlog4j2.configurationFile=std-log4j2.xml -jar target/log4j2-pattern-exp-slf4j
6+
7+
# pattern with exception message only:
8+
java -Dlog4j2.configurationFile=noex-log4j2.xml -jar target/log4j2-pattern-exp-slf4j
9+
```
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<groupId>cz.znj.kvr.sw.exp.java.logexp.log4j2</groupId>
5+
<artifactId>log4j2-pattern-exp</artifactId>
6+
<version>0.0.1</version>
7+
<packaging>jar</packaging>
8+
9+
<parent>
10+
<groupId>cz.znj.kvr.sw.exp.java.logexp.log4j2</groupId>
11+
<artifactId>log4j2-exp-base</artifactId>
12+
<version>0.0.1</version>
13+
<relativePath>../pom.xml</relativePath>
14+
</parent>
15+
16+
<build>
17+
<plugins>
18+
19+
<!-- the order matters - maven-shade-plugin somehow consumes the jar created by assembly-plugin -->
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-shade-plugin</artifactId>
23+
<executions>
24+
<execution>
25+
<phase>package</phase>
26+
<goals>
27+
<goal>shade</goal>
28+
</goals>
29+
<configuration>
30+
<finalName>${project.artifactId}-slf4j</finalName>
31+
<createDependencyReducedPom>false</createDependencyReducedPom>
32+
<filters>
33+
<filter>
34+
<artifact>*:${project.artifactId}-onejar</artifact>
35+
<excludes>
36+
<exclude>*</exclude>
37+
<exclude>**/*</exclude>
38+
</excludes>
39+
</filter>
40+
</filters>
41+
<transformers>
42+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
43+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
44+
<mainClass>com.github.kvr000.exp.java.logexp.log4j2.pattern.Slf4jMain</mainClass>
45+
</transformer>
46+
</transformers>
47+
</configuration>
48+
</execution>
49+
</executions>
50+
</plugin>
51+
52+
<plugin>
53+
<groupId>net.dryuf.maven.plugin</groupId>
54+
<artifactId>dryuf-executable-jar-maven-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<id>exec-shade</id>
58+
<phase>package</phase>
59+
<goals>
60+
<goal>create-executable</goal>
61+
</goals>
62+
<configuration>
63+
<vmParams>-Xmx256m</vmParams>
64+
<sort>true</sort>
65+
<resourceConfigs>
66+
<resourceConfig>
67+
<pattern>glob:*.jar</pattern>
68+
<minimalCompress>10</minimalCompress>
69+
</resourceConfig>
70+
</resourceConfigs>
71+
<input>${project.build.directory}/${project.artifactId}-slf4j.${project.packaging}</input>
72+
</configuration>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
77+
<plugin>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-maven-plugin</artifactId>
80+
</plugin>
81+
82+
83+
</plugins>
84+
</build>
85+
86+
<dependencies>
87+
<dependency>
88+
<groupId>org.projectlombok</groupId>
89+
<artifactId>lombok</artifactId>
90+
</dependency>
91+
92+
<dependency>
93+
<groupId>org.testng</groupId>
94+
<artifactId>testng</artifactId>
95+
<scope>test</scope>
96+
</dependency>
97+
98+
<dependency>
99+
<groupId>org.apache.logging.log4j</groupId>
100+
<artifactId>log4j-api</artifactId>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.apache.logging.log4j</groupId>
104+
<artifactId>log4j-core</artifactId>
105+
</dependency>
106+
107+
<dependency>
108+
<groupId>org.slf4j</groupId>
109+
<artifactId>slf4j-api</artifactId>
110+
</dependency>
111+
<dependency>
112+
<groupId>org.apache.logging.log4j</groupId>
113+
<artifactId>log4j-slf4j2-impl</artifactId>
114+
</dependency>
115+
116+
</dependencies>
117+
118+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.kvr000.exp.java.logexp.log4j2.pattern;
2+
3+
import lombok.extern.log4j.Log4j2;
4+
5+
6+
@Log4j2
7+
public class LogMain
8+
{
9+
public static void main(String[] args)
10+
{
11+
log.error("Hello World");
12+
try {
13+
Long.parseLong("hello");
14+
}
15+
catch (NumberFormatException ex) {
16+
log.error("Parse failed: ", ex);
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.kvr000.exp.java.logexp.log4j2.pattern;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
5+
6+
@Slf4j
7+
public class Slf4jMain
8+
{
9+
public static void main(String[] args)
10+
{
11+
log.error("Hello World");
12+
try {
13+
Long.parseLong("hello");
14+
}
15+
catch (NumberFormatException ex) {
16+
log.error("Parse failed: ", ex);
17+
}
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="INFO" monitorInterval="30">
3+
<Properties>
4+
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%throwable{1}%n</Property>
5+
</Properties>
6+
7+
<Appenders>
8+
<Console name="console" target="SYSTEM_OUT" follow="true">
9+
<PatternLayout pattern="${LOG_PATTERN}"/>
10+
</Console>
11+
</Appenders>
12+
13+
<Loggers>
14+
<Root level="Trace">
15+
<AppenderRef ref="console"/>
16+
</Root>
17+
</Loggers>
18+
</Configuration>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration status="WARN">
3+
<appenders>
4+
<console name="Console" target="SYSTEM_OUT">
5+
<patternLayout pattern="%d{yyyy-MM-dd'T'HH:mm:ss.SSS}{UTC}Z [%-16t] %-5level [%logger{36}] - %msg%n"/>
6+
</console>
7+
</appenders>
8+
<loggers>
9+
<logger name="com.github.kvr000.exp.java.opencv.basic" level="INFO" />
10+
11+
<root level="INFO">
12+
<appenderRef ref="Console" />
13+
</root>
14+
</loggers>
15+
</configuration>

log-exp/log4j2-exp/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<modules>
2626
<module>log4j2-logging-exp</module>
27+
<module>log4j2-pattern-exp</module>
2728
</modules>
2829

2930
<dependencyManagement>

log-exp/slf4j-exp/slf4j-cmdline-exp/README.md

100755100644
File mode changed.

0 commit comments

Comments
 (0)