Skip to content
Permalink
Browse files

[FIXED JENKINS-33817] Option to save backup copies of computation log.

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 355600a4c7232c1b28fefe71a7c8dcb6d5fdc640
@@ -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;

@@ -68,6 +69,10 @@

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;

@@ -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;

0 comments on commit 355600a

Please sign in to comment.
You can’t perform that action at this time.