This is an automated email from the ASF dual-hosted git repository.

cameronlee pushed a commit to branch latest
in repository https://gitbox.apache.org/repos/asf/samza-hello-samza.git


The following commit(s) were added to refs/heads/latest by this push:
     new 751e03d  SAMZA-2433: Use log4j2 in samza-hello-samza (#70)
751e03d is described below

commit 751e03df0bac97e2dfba7bc34d66fd30a074a751
Author: Cameron Lee <[email protected]>
AuthorDate: Thu Jan 23 16:24:36 2020 -0800

    SAMZA-2433: Use log4j2 in samza-hello-samza (#70)
---
 build.gradle                       |  23 ++++---
 pom.xml                            | 132 +++++++++++++++++++++++++++++--------
 src/main/assembly/src.xml          |   2 +-
 src/main/resources/log4j.xml       |  52 ---------------
 src/main/resources/log4j2.xml      |  52 +++++++++++++++
 src/test/resources/log4j2-test.xml |  37 +++++++++++
 6 files changed, 210 insertions(+), 88 deletions(-)

diff --git a/build.gradle b/build.gradle
index 9c807c7..427409c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -49,25 +49,32 @@ configurations {
     explode
 }
 
+configurations.all {
+    // using log4j1 to log4j2 bridge so need to exclude log4j1
+    exclude group: 'log4j', module: 'log4j'
+    // exclude all other slf4j bindings that are transitively pulled in
+    exclude group: 'org.slf4j', module: 'slf4j-log4j12'
+}
+
 dependencies {
     compile(group: 'org.codehaus.jackson', name: 'jackson-jaxrs', version: 
'1.9.13')
     compile(group: 'org.slf4j', name: 'slf4j-api', version: "$SLF4J_VERSION")
-    compile(group: 'org.slf4j', name: 'slf4j-log4j12', version: 
"$SLF4J_VERSION")
     compile(group: 'org.schwering', name: 'irclib', version: '1.10')
     compile(group: 'org.apache.samza', name: 'samza-api', version: 
"$SAMZA_VERSION")
-    compile(group: 'org.apache.samza', name: 'samza-kv_2.11', version: 
"$SAMZA_VERSION")
-    compile(group: 'org.apache.samza', name: 'samza-test_2.11', version: 
"$SAMZA_VERSION")
+    compile(group: 'org.apache.samza', name: 'samza-azure_2.11', version: 
"$SAMZA_VERSION")
     compile(group: 'org.apache.samza', name: 'samza-kafka_2.11', version: 
"$SAMZA_VERSION")
+    compile(group: 'org.apache.samza', name: 'samza-kv_2.11', version: 
"$SAMZA_VERSION")
+    compile(group: 'org.apache.samza', name: 'samza-kv-couchbase_2.11', 
version: "$SAMZA_VERSION")
     compile(group: 'org.apache.samza', name: 'samza-kv-rocksdb_2.11', version: 
"$SAMZA_VERSION")
-    compile(group: 'org.apache.samza', name: 'samza-azure_2.11', version: 
"$SAMZA_VERSION")
-    testCompile(group: 'junit', name: 'junit', version: "4.12")
-    explode (group: 'org.apache.samza', name: 'samza-shell',  ext: 'tgz', 
classifier: 'dist', version: "$SAMZA_VERSION")
+    explode(group: 'org.apache.samza', name: 'samza-shell',  ext: 'tgz', 
classifier: 'dist', version: "$SAMZA_VERSION")
     runtime(group: 'org.apache.samza', name: 'samza-core_2.11', version: 
"$SAMZA_VERSION")
-    runtime(group: 'org.apache.samza', name: 'samza-log4j_2.11', version: 
"$SAMZA_VERSION")
+    runtime(group: 'org.apache.samza', name: 'samza-log4j2_2.11', version: 
"$SAMZA_VERSION")
     runtime(group: 'org.apache.samza', name: 'samza-shell', version: 
"$SAMZA_VERSION")
     runtime(group: 'org.apache.samza', name: 'samza-yarn_2.11', version: 
"$SAMZA_VERSION")
     runtime(group: 'org.apache.kafka', name: 'kafka_2.11', version: 
"$KAFKA_VERSION")
     runtime(group: 'org.apache.hadoop', name: 'hadoop-hdfs', version: 
"$HADOOP_VERSION")
+    testCompile(group: 'org.apache.samza', name: 'samza-test_2.11', version: 
"$SAMZA_VERSION")
+    testCompile(group: 'junit', name: 'junit', version: "4.12")
 }
 
 // make the samza distribution .tgz file
@@ -100,7 +107,7 @@ task distTar(dependsOn: build, type: Tar) {
         from configurations.runtime
         from configurations.runtime.artifacts.files
         from("src/main/resources/") {
-            include "log4j.xml"
+            include "log4j2.xml"
         }
     }
 }
diff --git a/pom.xml b/pom.xml
index 6c0e7e3..49f4eff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,6 +61,17 @@ under the License.
       <groupId>org.apache.samza</groupId>
       <artifactId>samza-core_2.11</artifactId>
       <version>${samza.version}</version>
+      <exclusions>
+        <!-- zookeeper dependency pulls in log4j1; exclude log4j1 components 
since we want to use log4j2 components -->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.samza</groupId>
@@ -95,14 +106,8 @@ under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.samza</groupId>
-      <artifactId>samza-log4j_2.11</artifactId>
+      <artifactId>samza-log4j2_2.11</artifactId>
       <version>${samza.version}</version>
-      <exclusions>
-       <exclusion>
-        <groupId>org.apache.samza</groupId>
-        <artifactId>samza-core_2.12</artifactId>
-       </exclusion>
-      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.samza</groupId>
@@ -115,6 +120,17 @@ under the License.
       <groupId>org.apache.samza</groupId>
       <artifactId>samza-yarn_2.11</artifactId>
       <version>${samza.version}</version>
+      <exclusions>
+        <!-- zookeeper dependency pulls in log4j1; exclude log4j1 components 
since we want to use log4j2 components -->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.samza</groupId>
@@ -132,16 +148,6 @@ under the License.
       <version>${samza.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.samza</groupId>
-      <artifactId>samza-aws_2.11</artifactId>
-      <version>${samza.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.kafka</groupId>
-      <artifactId>kafka_2.11</artifactId>
-      <version>0.11.0.2</version>
-    </dependency>
-    <dependency>
       <groupId>org.schwering</groupId>
       <artifactId>irclib</artifactId>
       <version>1.10</version>
@@ -152,54 +158,126 @@ under the License.
       <version>1.6.2</version>
     </dependency>
     <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-log4j12</artifactId>
-      <version>1.6.2</version>
-    </dependency>
-    <dependency>
       <groupId>org.codehaus.jackson</groupId>
       <artifactId>jackson-jaxrs</artifactId>
       <version>1.9.13</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpcore</artifactId>
+      <version>4.4.1</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-annotations</artifactId>
       <version>${hadoop.version}</version>
+      <exclusions>
+        <!-- exclude log4j1 components since we want to use log4j2 components 
-->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-auth</artifactId>
       <version>${hadoop.version}</version>
+      <exclusions>
+        <!-- exclude log4j1 components since we want to use log4j2 components 
-->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-common</artifactId>
       <version>${hadoop.version}</version>
-    </dependency>
-   <dependency>
-    <groupId>org.apache.httpcomponents</groupId>
-    <artifactId>httpcore</artifactId>
-    <version>4.4.1</version>
+      <exclusions>
+        <!-- exclude log4j1 components since we want to use log4j2 components 
-->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-hdfs</artifactId>
       <version>${hadoop.version}</version>
+      <exclusions>
+        <!-- exclude log4j1 components since we want to use log4j2 components 
-->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-yarn-api</artifactId>
       <version>${hadoop.version}</version>
+      <exclusions>
+        <!-- exclude log4j1 components since we want to use log4j2 components 
-->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-yarn-client</artifactId>
       <version>${hadoop.version}</version>
+      <exclusions>
+        <!-- exclude log4j1 components since we want to use log4j2 components 
-->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-yarn-common</artifactId>
       <version>${hadoop.version}</version>
+      <exclusions>
+        <!-- exclude log4j1 components since we want to use log4j2 components 
-->
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>com.google.guava</groupId>
diff --git a/src/main/assembly/src.xml b/src/main/assembly/src.xml
index 1614aaf..5fac44a 100644
--- a/src/main/assembly/src.xml
+++ b/src/main/assembly/src.xml
@@ -41,7 +41,7 @@
   </fileSets>
   <files>
     <file>
-      <source>${basedir}/src/main/resources/log4j.xml</source>
+      <source>${basedir}/src/main/resources/log4j2.xml</source>
       <outputDirectory>lib</outputDirectory>
     </file>
     <file>
diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml
deleted file mode 100644
index 805d5ca..0000000
--- a/src/main/resources/log4j.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements.  See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership.  The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied.  See the License for the
- specific language governing permissions and limitations
- under the License.
-
--->
-
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
-  <appender name="jmx" class="org.apache.samza.logging.log4j.JmxAppender" />
-
-  <appender name="RollingAppender" 
class="org.apache.log4j.RollingFileAppender">
-     <param name="File" value="${samza.log.dir}/${samza.container.name}.log" />
-     <param name="MaxFileSize" value="256MB" />
-     <param name="MaxBackupIndex" value="20" />
-     <layout class="org.apache.log4j.PatternLayout">
-      <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] 
%c{1} [%p] %m%n" />
-     </layout>
-  </appender>
-  <appender name="StartupAppender" 
class="org.apache.log4j.RollingFileAppender">
-     <param name="File" 
value="${samza.log.dir}/${samza.container.name}-startup.log" />
-     <param name="MaxFileSize" value="256MB" />
-     <param name="MaxBackupIndex" value="1" />
-     <layout class="org.apache.log4j.PatternLayout">
-      <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] 
%c{1} [%p] %m%n" />
-     </layout>
-  </appender>
-  <logger name="STARTUP_LOGGER" additivity="false">
-    <level value="info" />
-    <appender-ref ref="StartupAppender"/>
-  </logger>
-  <root>
-    <priority value="info" />
-    <appender-ref ref="RollingAppender"/>
-    <appender-ref ref="jmx" />
-  </root>
-</log4j:configuration>
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..adcdadb
--- /dev/null
+++ b/src/main/resources/log4j2.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<Configuration>
+  <Appenders>
+    <RollingFile name="RollingFile" 
fileName="${sys:samza.log.dir}/${sys:samza.container.name}.log"
+                 
filePattern="${sys:samza.log.dir}/${sys:samza.container.name}-%d{yyyy-MM-dd}-%i.log">
+      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} [%p] 
%m%n"/>
+      <Policies>
+        <SizeBasedTriggeringPolicy size="256MB" />
+      </Policies>
+      <DefaultRolloverStrategy max="20"/>
+    </RollingFile>
+
+    <RollingFile name="StartupAppender" 
fileName="${sys:samza.log.dir}/${sys:samza.container.name}-startup.log"
+                 
filePattern="${sys:samza.log.dir}/${sys:samza.container.name}-startup-%d{MM-dd-yyyy}-%i.log">
+      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} [%p] 
%m%n"/>
+      <Policies>
+        <SizeBasedTriggeringPolicy size="256MB" />
+      </Policies>
+      <DefaultRolloverStrategy max="1"/>
+    </RollingFile>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="STARTUP_LOGGER" level="info" additivity="false">
+      <AppenderRef ref="StartupAppender"/>
+    </Logger>
+    <Root level="info">
+      <AppenderRef ref="RollingFile"/>
+    </Root>
+  </Loggers>
+</Configuration>
diff --git a/src/test/resources/log4j2-test.xml 
b/src/test/resources/log4j2-test.xml
new file mode 100644
index 0000000..c095c00
--- /dev/null
+++ b/src/test/resources/log4j2-test.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<!-- this is needed to avoid using src/main/resources/log4j2.xml for tests -->
+
+<Configuration>
+  <Appenders>
+    <Console name="STDOUT" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} [%p] 
%m%n"/>
+    </Console>
+  </Appenders>
+
+  <Loggers>
+    <Root level="info">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+</Configuration>

Reply via email to