-
Notifications
You must be signed in to change notification settings - Fork 624
HDDS-8534. Enable asynchronous service logging #4663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e9633d5
HDDS-8534. Enable asynchronous service logging
tanvipenumudy a34c8d6
Fix inconsistent synchronization of org.apache.hadoop.ozone.utils.Asy…
tanvipenumudy d0c7907
Make getConversionPattern() synchronized
tanvipenumudy d0e2e91
Make setConversionPattern() synchronized
tanvipenumudy 9e6b6b1
Address review comments
tanvipenumudy c35eaf0
Remove ASYNCRFA from default
tanvipenumudy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/AsyncRollingFileAppender.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/utils/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.