Skip to content

Commit

Permalink
[FIXED JENKINS-33817] Option to save backup copies of computation log.
Browse files Browse the repository at this point in the history
Pass -Dcom.cloudbees.hudson.plugins.folder.computed.FolderComputation.BACKUP_LOG_COUNT=5
to save computation.log.1–computation.log.5 as backups.
  • Loading branch information
jglick committed Mar 29, 2016
1 parent b8a4fd6 commit 355600a
Showing 1 changed file with 14 additions and 1 deletion.
Expand Up @@ -57,6 +57,7 @@

import hudson.util.AlternativeUiTextProvider;
import hudson.util.AlternativeUiTextProvider.Message;
import hudson.util.io.ReopenableRotatingFileOutputStream;
import org.apache.commons.io.Charsets;
import org.apache.commons.jelly.XMLOutput;

Expand All @@ -68,6 +69,10 @@ public class FolderComputation<I extends TopLevelItem> extends Actionable implem

private static final Logger LOGGER = Logger.getLogger(FolderComputation.class.getName());

/** If defined, a number of backup log files to keep. */
@SuppressWarnings("FieldMayBeFinal") // let this be set dynamically by system Groovy script
private static @CheckForNull Integer BACKUP_LOG_COUNT = Integer.getInteger(FolderComputation.class.getName() + ".BACKUP_LOG_COUNT");

/** The associated folder. */
private transient final @Nonnull ComputedFolder<I> folder;

Expand Down Expand Up @@ -95,7 +100,15 @@ protected FolderComputation(@Nonnull ComputedFolder<I> folder, @CheckForNull Fol
public void run() {
StreamBuildListener listener;
try {
listener = new StreamBuildListener(new FileOutputStream(getLogFile()), Charsets.UTF_8);
File logFile = getLogFile();
OutputStream os;
if (BACKUP_LOG_COUNT != null) {
os = new ReopenableRotatingFileOutputStream(logFile, BACKUP_LOG_COUNT);
((ReopenableRotatingFileOutputStream) os).rewind();
} else {
os = new FileOutputStream(logFile);
}
listener = new StreamBuildListener(os, Charsets.UTF_8);
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
result = Result.FAILURE;
Expand Down

0 comments on commit 355600a

Please sign in to comment.