This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 17802a08f4 HDDS-8534. Support asynchronous service logging (#4663)
17802a08f4 is described below
commit 17802a08f45655835109b65a318eb1233fa4177f
Author: tanvipenumudy <[email protected]>
AuthorDate: Thu Jun 22 15:38:07 2023 +0530
HDDS-8534. Support asynchronous service logging (#4663)
---
hadoop-ozone/dist/src/shell/conf/log4j.properties | 8 ++
.../ozone/utils/AsyncRollingFileAppender.java | 128 +++++++++++++++++++++
.../apache/hadoop/ozone/utils/package-info.java | 23 ++++
3 files changed, 159 insertions(+)
diff --git a/hadoop-ozone/dist/src/shell/conf/log4j.properties
b/hadoop-ozone/dist/src/shell/conf/log4j.properties
index 74e2ac515a..96e90ab541 100644
--- a/hadoop-ozone/dist/src/shell/conf/log4j.properties
+++ b/hadoop-ozone/dist/src/shell/conf/log4j.properties
@@ -46,6 +46,14 @@ log4j.appender.RFA.layout.ConversionPattern=%d{ISO8601} [%t]
%p %c: %m%n
# Debugging Pattern format
#log4j.appender.RFA.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c{2}
(%F:%M(%L)) - %m%n
+#
+# Async Rolling File Appender
+#
+log4j.appender.ASYNCRFA=org.apache.hadoop.ozone.utils.AsyncRollingFileAppender
+log4j.appender.ASYNCRFA.fileName=${hadoop.log.dir}/${hadoop.log.file}
+log4j.appender.ASYNCRFA.maxFileSize=${hadoop.log.maxfilesize}
+log4j.appender.ASYNCRFA.maxBackupIndex=${hadoop.log.maxbackupindex}
+log4j.appender.ASYNCRFA.conversionPattern=%d{ISO8601} [%t] %p %c: %m%n
#
# Daily Rolling File Appender
diff --git
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AsyncRollingFileAppender.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AsyncRollingFileAppender.java
new file mode 100644
index 0000000000..3db6af5ec1
--- /dev/null
+++
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AsyncRollingFileAppender.java
@@ -0,0 +1,128 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+package org.apache.hadoop.ozone.utils;
+
+import java.io.IOException;
+
+import org.apache.log4j.AsyncAppender;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.RollingFileAppender;
+import org.apache.log4j.spi.LoggingEvent;
+
+/**
+ * The AsyncRollingFileAppender shall take the required parameters for
supplying
+ * RollingFileAppender to AsyncAppender.
+ */
+public class AsyncRollingFileAppender extends AsyncAppender {
+
+ private String maxFileSize = String.valueOf(10 * 1024 * 1024);
+
+ private int maxBackupIndex = 1;
+
+ private String fileName = null;
+
+ private String conversionPattern = null;
+
+ private boolean blocking = true;
+
+ private int bufferSize = DEFAULT_BUFFER_SIZE;
+
+ private RollingFileAppender rollingFileAppender = null;
+
+ private volatile boolean isRollingFileAppenderAssigned = false;
+
+ @Override
+ public void append(LoggingEvent event) {
+ if (rollingFileAppender == null) {
+ createRollingFileAppender();
+ }
+ super.append(event);
+ }
+
+ private synchronized void createRollingFileAppender() {
+ if (!isRollingFileAppenderAssigned) {
+ PatternLayout patternLayout;
+ if (conversionPattern != null) {
+ patternLayout = new PatternLayout(conversionPattern);
+ } else {
+ patternLayout = new PatternLayout();
+ }
+ try {
+ rollingFileAppender =
+ new RollingFileAppender(patternLayout, fileName, true);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ rollingFileAppender.setMaxBackupIndex(maxBackupIndex);
+ rollingFileAppender.setMaxFileSize(maxFileSize);
+ this.addAppender(rollingFileAppender);
+ isRollingFileAppenderAssigned = true;
+ super.setBlocking(blocking);
+ super.setBufferSize(bufferSize);
+ }
+ }
+
+ public synchronized String getMaxFileSize() {
+ return maxFileSize;
+ }
+
+ public synchronized void setMaxFileSize(String maxFileSize) {
+ this.maxFileSize = maxFileSize;
+ }
+
+ public synchronized int getMaxBackupIndex() {
+ return maxBackupIndex;
+ }
+
+ public synchronized void setMaxBackupIndex(int maxBackupIndex) {
+ this.maxBackupIndex = maxBackupIndex;
+ }
+
+ public synchronized String getFileName() {
+ return fileName;
+ }
+
+ public synchronized void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public synchronized String getConversionPattern() {
+ return conversionPattern;
+ }
+
+ public synchronized void setConversionPattern(String conversionPattern) {
+ this.conversionPattern = conversionPattern;
+ }
+
+ public boolean isBlocking() {
+ return blocking;
+ }
+
+ public synchronized void setBlocking(boolean blocking) {
+ this.blocking = blocking;
+ }
+
+ public synchronized int getBufferSize() {
+ return bufferSize;
+ }
+
+ public synchronized void setBufferSize(int bufferSize) {
+ this.bufferSize = bufferSize;
+ }
+}
diff --git
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/package-info.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/package-info.java
new file mode 100644
index 0000000000..a18745d470
--- /dev/null
+++
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+/**
+ * Utility classes for Ozone.
+ */
+package org.apache.hadoop.ozone.utils;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]