You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2016/07/13 20:09:28 UTC
[24/50] [abbrv] logging-log4j2 git commit: LOG4J2-1440 - Do not
delete files if OnStartupTriggeringPolicy has a minSize of 0.
LOG4J2-1440 - Do not delete files if OnStartupTriggeringPolicy has a minSize of 0.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b0b4f865
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b0b4f865
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b0b4f865
Branch: refs/heads/feature/LOG4J2-1430
Commit: b0b4f86596302b55d51b1b58f9809ff97fa9e646
Parents: bd077fc
Author: Ralph Goers <rg...@nextiva.com>
Authored: Sat Jul 2 13:02:59 2016 -0700
Committer: Ralph Goers <rg...@nextiva.com>
Committed: Sat Jul 2 13:03:53 2016 -0700
----------------------------------------------------------------------
.../core/appender/rolling/DefaultRolloverStrategy.java | 9 +++++----
.../core/appender/rolling/OnStartupTriggeringPolicy.java | 3 +++
.../log4j/core/appender/rolling/RollingFileManager.java | 9 +++++++++
3 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b0b4f865/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
index 2a83861..dd1f42c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
@@ -181,7 +181,7 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
/**
* Create the DefaultRolloverStrategy.
- *
+ *
* @param max The maximum number of files to keep.
* @param min The minimum number of files to keep.
* @param fileIndex If set to "max" (the default), files with a higher index will be newer than files with a smaller
@@ -243,7 +243,7 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
/**
* Constructs a new instance.
- *
+ *
* @param minIndex The minimum index.
* @param maxIndex The maximum index.
* @param customActions custom actions to perform asynchronously after rollover
@@ -510,7 +510,7 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
/**
* Perform the rollover.
- *
+ *
* @param manager The RollingFileManager name for current active log file.
* @return A RolloverDescription.
* @throws SecurityException if an error occurs.
@@ -545,7 +545,8 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
}
}
- final FileRenameAction renameAction = new FileRenameAction(new File(currentFileName), new File(renameTo), false);
+ final FileRenameAction renameAction = new FileRenameAction(new File(currentFileName), new File(renameTo),
+ manager.isRenameEmptyFiles());
final Action asyncAction = merge(compressAction, customActions, stopCustomActionsOnError);
return new RolloverDescriptionImpl(currentFileName, false, renameAction, asyncAction);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b0b4f865/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicy.java
index 12e2b23..a380028 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicy.java
@@ -75,6 +75,9 @@ public class OnStartupTriggeringPolicy implements TriggeringPolicy {
@Override
public void initialize(final RollingFileManager manager) {
if (manager.getFileTime() < JVM_START_TIME && manager.getFileSize() >= minSize) {
+ if (minSize == 0) {
+ manager.setRenameEmptyFiles(true);
+ }
manager.skipFooter(true);
manager.rollover();
manager.skipFooter(false);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b0b4f865/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
index 1caeeb3..9b721bc 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
@@ -48,6 +48,7 @@ public class RollingFileManager extends FileManager {
private final Semaphore semaphore = new Semaphore(1);
private volatile TriggeringPolicy triggeringPolicy;
private volatile RolloverStrategy rolloverStrategy;
+ private volatile boolean renameEmptyFiles = false;
private static final AtomicReferenceFieldUpdater<RollingFileManager, TriggeringPolicy> triggeringPolicyUpdater =
AtomicReferenceFieldUpdater.newUpdater(RollingFileManager.class, TriggeringPolicy.class, "triggeringPolicy");
@@ -115,6 +116,14 @@ public class RollingFileManager extends FileManager {
super.writeToDestination(bytes, offset, length);
}
+ public boolean isRenameEmptyFiles() {
+ return renameEmptyFiles;
+ }
+
+ public void setRenameEmptyFiles(boolean renameEmptyFiles) {
+ this.renameEmptyFiles = renameEmptyFiles;
+ }
+
/**
* Returns the current size of the file.
* @return The size of the file in bytes.