[
https://issues.apache.org/jira/browse/LOG4J2-1766?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16063325#comment-16063325
]
ASF GitHub Bot commented on LOG4J2-1766:
----------------------------------------
Github user garydgregory commented on a diff in the pull request:
https://github.com/apache/logging-log4j2/pull/88#discussion_r124051596
--- Diff:
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
---
@@ -83,6 +85,195 @@
private static final int DEFAULT_WINDOW_SIZE = 7;
/**
+ * Builds DefaultRolloverStrategy instances.
+ */
+ public static class Builder implements
org.apache.logging.log4j.core.util.Builder<DefaultRolloverStrategy> {
+ @PluginBuilderAttribute("max")
+ private String max;
+
+ @PluginBuilderAttribute("min")
+ private String min;
+
+ @PluginBuilderAttribute("fileIndex")
+ private String fileIndex;
+
+ @PluginBuilderAttribute("compressionLevel")
+ private String compressionLevelStr;
+
+ @PluginElement("Actions")
+ private Action[] customActions;
+
+ @PluginBuilderAttribute(value = "stopCustomActionsOnError")
+ private boolean stopCustomActionsOnError = true;
+
+ @PluginBuilderAttribute(value = "compressTmpFilePattern")
+ private String compressTmpFilePattern;
+
+ @PluginConfiguration
+ private Configuration config;
+
+ @Override
+ public DefaultRolloverStrategy build() {
+ int minIndex;
+ int maxIndex;
+ boolean useMax;
+
+ if (fileIndex != null && fileIndex.equalsIgnoreCase("nomax")) {
+ minIndex = Integer.MIN_VALUE;
+ maxIndex = Integer.MAX_VALUE;
+ useMax = false;
+ } else {
+ useMax = fileIndex == null ? true :
fileIndex.equalsIgnoreCase("max");
+ minIndex = MIN_WINDOW_SIZE;
+ if (min != null) {
+ minIndex = Integer.parseInt(min);
+ if (minIndex < 1) {
+ LOGGER.error("Minimum window size too small.
Limited to " + MIN_WINDOW_SIZE);
+ minIndex = MIN_WINDOW_SIZE;
+ }
+ }
+ maxIndex = DEFAULT_WINDOW_SIZE;
+ if (max != null) {
+ maxIndex = Integer.parseInt(max);
+ if (maxIndex < minIndex) {
+ maxIndex = minIndex < DEFAULT_WINDOW_SIZE ?
DEFAULT_WINDOW_SIZE : minIndex;
+ LOGGER.error("Maximum window size must be greater
than the minimum windows size. Set to " + maxIndex);
+ }
+ }
+ }
+ final int compressionLevel =
Integers.parseInt(compressionLevelStr, Deflater.DEFAULT_COMPRESSION);
+ return new DefaultRolloverStrategy(minIndex, maxIndex, useMax,
compressionLevel, config.getStrSubstitutor(),
+ customActions, stopCustomActionsOnError,
compressTmpFilePattern);
+ }
+
+ public String getMax() {
+ return max;
+ }
+
+ /**
+ * Define the maximum number of files to keep.
--- End diff --
Javadoc comments should use the active voice, IOW, "Defines..." instead of
"Define...". So you can read it as "The method foo defines...".
> Distinguish between partial and completed .gz archive file
> ----------------------------------------------------------
>
> Key: LOG4J2-1766
> URL: https://issues.apache.org/jira/browse/LOG4J2-1766
> Project: Log4j 2
> Issue Type: New Feature
> Affects Versions: 2.5
> Reporter: Sameer Pradhan
> Labels: features
>
> I have the following log configuration.
> {code:xml}
> <RollingRandomAccessFile name="RollingReqAppender"
> fileName="/usr/test/req.log"
> filePattern="/usr/test/req.log.%d{yyyy-MM-dd-HH}.%i.gz"
> immediateFlush="true" append="true">
> <PatternLayout>
> <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS Z}%m%n</Pattern>
> </PatternLayout>
> <Policies>
> <SizeBasedTriggeringPolicy size="500 MB"/>
> <TimeBasedTriggeringPolicy interval="1" modulate="true" />
> </Policies>
> </RollingRandomAccessFile>
> {code}
> When the log is rolled over (based on time or size), it is gzipped. Gzipping
> the file takes some time (seconds to minutes depending on load). The problem
> is that the file is gzipped in place, and while it is being gzipped, the
> partially gzipped file is stored in the same folder with the same name as the
> final gzip file. e.g.: {{/usr/test/req.log.2017-01-03-02.1.gz}}
> This causes problems for the file's consumer, which attempts to process the
> partial file. I want to be able to distinguish between a partial gzipped file
> and a completed gzipped file. For example, I would like to setup a
> configuration that while the file is being gzipped, it is written with a
> different name e.g.: {{/usr/test/req.log.2017-01-03-02.1.gz.temp}} and once
> it is completely gzipped the name is changed to the final name
> {{/usr/test/req.log.2017-01-03-02.1.gz}}
> One way to achieve this is to add a new parameter like
> "temporaryCompressedFilePattern" as follows:
> {code:xml}
> <RollingRandomAccessFile name="RollingReqAppender"
> fileName="/usr/test/req.log"
> filePattern="/usr/test/req.log.%d{yyyy-MM-dd-HH}.%i.gz"
>
> temporaryCompressedFilePattern="/usr/test/req.log.%d{yyyy-MM-dd-HH}.%i.gz.temp"
> {code}
> Another option is to make such behavior the default behavior without adding a
> new parameter.
>
> This was first discussed at
> http://stackoverflow.com/questions/41457492/partial-gz-file-written-by-log4j2
> Creating this feature request as suggested by @rpopma
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)