Skip to content

Commit

Permalink
ZOOKEEPER-4461: Use logback in zookeeper-contrib project
Browse files Browse the repository at this point in the history
I've only found Ant references in the `-recipes` projects which I don't necesseraly want to migrate, so this patch is focusing on `-contrib` projects.

Please review.

Author: Andor Molnar <[email protected]>

Reviewers: Enrico Olivelli <[email protected]>

Closes apache#1807 from anmolnar/ZOOKEEPER-4461
  • Loading branch information
anmolnar authored and eolivelli committed Feb 1, 2022
1 parent 1bdba02 commit 04c7ad1
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 149 deletions.
18 changes: 0 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@
<jmockit.version>1.48</jmockit.version>
<junit.version>5.6.2</junit.version>
<junit-platform.version>1.6.2</junit-platform.version>
<log4j.version>1.2.17</log4j.version>
<mockito.version>3.6.28</mockito.version>
<hamcrest.version>2.2</hamcrest.version>
<commons-cli.version>1.4</commons-cli.version>
Expand Down Expand Up @@ -563,22 +562,6 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
Expand Down Expand Up @@ -1009,7 +992,6 @@
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/log4j.properties</exclude>
<exclude>**/README.md</exclude>
<exclude>**/findbugsExcludeFile.xml</exclude>
<exclude>**/checkstyle-noframes-sorted.xsl</exclude>
Expand Down
2 changes: 1 addition & 1 deletion zookeeper-client/zookeeper-client-c/src/zk_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static const char* time_now(char* now_str){
now = tv.tv_sec;
localtime_r(&now, &lt);

// clone the format used by log4j ISO8601DateFormat
// clone the format used by logback ISO8601DateFormat
// specifically: "yyyy-MM-dd HH:mm:ss,SSS"

len = strftime(now_str, TIME_NOW_BUF_SIZE,
Expand Down
6 changes: 3 additions & 3 deletions zookeeper-contrib/zookeeper-contrib-fatjar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
<artifactId>snappy-java</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
</dependencies>

Expand All @@ -104,7 +104,7 @@
<resource>
<directory>${project.basedir}/../../conf</directory>
<includes>
<include>log4j.properties</include>
<include>logback.xml</include>
</includes>
</resource>
</resources>
Expand Down
14 changes: 2 additions & 12 deletions zookeeper-contrib/zookeeper-contrib-loggraph/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,8 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private void init() throws IOException {
if ((line != null) && (m = timep.matcher(line)).lookingAt()) {
starttime = timestampFromText(dateformat, m.group(1));
} else {
throw new IOException("Invalid log4j format. First line doesn't start with time");
throw new IOException("Invalid log format. First line doesn't start with time");
}

/*
Expand Down Expand Up @@ -328,7 +328,7 @@ private void init() throws IOException {
if (m.lookingAt()) {
endtime = timestampFromText(dateformat, m.group(1));
} else {
throw new IOException("Invalid log4j format. Last line doesn't start with time");
throw new IOException("Invalid log format. Last line doesn't start with time");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ done

CLASSPATH=$BUILDDIR/classes:$WEBDIR:$CLASSPATH
echo $CLASSPATH
java -Dlog4j.configuration=org/apache/zookeeper/graph/log4j.properties -Xdebug -Xrunjdwp:transport=dt_socket,address=4444,server=y,suspend=n -cp $CLASSPATH org.apache.zookeeper.graph.LogServer $*
java -Dlogback.configurationFile=org/apache/zookeeper/graph/logback.xml -Xdebug -Xrunjdwp:transport=dt_socket,address=4444,server=y,suspend=n -cp $CLASSPATH org.apache.zookeeper.graph.LogServer $*

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
Copyright 2022 The Apache Software Foundation
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.
Define some default values that can be overridden by system properties
-->
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>TRACE</level>
</filter>
</appender>

<logger name="org.apache.zookeeper.graph.LogSkipList" level="off"/>
<logger name="org.apache.zookeeper.graph.RandomAccessFileReader" level="off"/>

<root level="TRACE">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
68 changes: 0 additions & 68 deletions zookeeper-contrib/zookeeper-contrib-rest/conf/log4j.properties

This file was deleted.

114 changes: 114 additions & 0 deletions zookeeper-contrib/zookeeper-contrib-rest/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<!--
Copyright 2022 The Apache Software Foundation
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.
Define some default values that can be overridden by system properties
-->
<configuration>
<!-- Uncomment this if you would like to expose Logback JMX beans -->
<!--jmxConfigurator /-->

<property name="zookeeper.console.threshold" value="INFO" />

<property name="zookeeper.log.dir" value="." />
<property name="zookeeper.log.file" value="zookeeper.log" />
<property name="zookeeper.log.threshold" value="INFO" />
<property name="zookeeper.log.maxfilesize" value="256MB" />
<property name="zookeeper.log.maxbackupindex" value="20" />

<!--
console
Add "console" to root logger if you want to use this
-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${zookeeper.console.threshold}</level>
</filter>
</appender>

<!--
Add ROLLINGFILE to root logger to get log file output
-->
<!--appender name="ROLLINGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${zookeeper.log.dir}/${zookeeper.log.file}</File>
<encoder>
<pattern>%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${zookeeper.log.threshold}</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<maxIndex>${zookeeper.log.maxbackupindex}</maxIndex>
<FileNamePattern>${zookeeper.log.dir}/${zookeeper.log.file}.%i</FileNamePattern>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>${zookeeper.log.maxfilesize}</MaxFileSize>
</triggeringPolicy>
</appender-->

<!--
Add TRACEFILE to root logger to get log file output
Log TRACE level and above messages to a log file
-->
<!--property name="zookeeper.tracelog.dir" value="${zookeeper.log.dir}" />
<property name="zookeeper.tracelog.file" value="zookeeper_trace.log" />
<appender name="TRACEFILE" class="ch.qos.logback.core.FileAppender">
<File>${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}</File>
<encoder>
<pattern>%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>TRACE</level>
</filter>
</appender-->

<!--
zk audit logging
-->
<!--property name="zookeeper.auditlog.file" value="zookeeper_audit.log" />
<property name="zookeeper.auditlog.threshold" value="INFO" />
<property name="audit.logger" value="INFO, RFAAUDIT" />
<appender name="RFAAUDIT" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${zookeeper.log.dir}/${zookeeper.auditlog.file}</File>
<encoder>
<pattern>%d{ISO8601} %p %c{2}: %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${zookeeper.auditlog.threshold}</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<maxIndex>10</maxIndex>
<FileNamePattern>${zookeeper.log.dir}/${zookeeper.auditlog.file}.%i</FileNamePattern>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<logger name="org.apache.zookeeper.audit.Slf4jAuditLogger" additivity="false" level="${audit.logger}">
<appender-ref ref="RFAAUDIT" />
</logger-->

<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
14 changes: 2 additions & 12 deletions zookeeper-contrib/zookeeper-contrib-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,8 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand Down
14 changes: 2 additions & 12 deletions zookeeper-contrib/zookeeper-contrib-zooinspector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,8 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand Down
Loading

0 comments on commit 04c7ad1

Please sign in to comment.