Skip to content

Commit

Permalink
Merge pull request #140 from batmat/JENKINS-50428
Browse files Browse the repository at this point in the history
[JENKINS-50428] Take into account the now configurable location for (tasks) logging
  • Loading branch information
batmat committed Mar 29, 2018
2 parents 7dff475 + e0bf6ba commit 132c99f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/com/cloudbees/jenkins/support/impl/JenkinsLogs.java
Expand Up @@ -46,7 +46,7 @@ public class JenkinsLogs extends Component {
private static final Logger LOGGER = Logger.getLogger(JenkinsLogs.class.getName()); private static final Logger LOGGER = Logger.getLogger(JenkinsLogs.class.getName());
private static final int MAX_ROTATE_LOGS = Integer.getInteger(JenkinsLogs.class.getName() + ".MAX_ROTATE_LOGS", 9); private static final int MAX_ROTATE_LOGS = Integer.getInteger(JenkinsLogs.class.getName() + ".MAX_ROTATE_LOGS", 9);
private final Map<String,LogRecorder> logRecorders = Jenkins.getInstance().getLog().logRecorders; private final Map<String,LogRecorder> logRecorders = Jenkins.getInstance().getLog().logRecorders;
private final File customLogs = new File(new File(Jenkins.getInstance().getRootDir(), "logs"), "custom"); private final File customLogs = new File(getLogsRoot(), "custom");


@NonNull @NonNull
@Override @Override
Expand Down Expand Up @@ -111,7 +111,7 @@ private void addOtherMasterLogs(Container result) {
result.add(new FileContent("other-logs/" + f.getName(), f)); result.add(new FileContent("other-logs/" + f.getName(), f));
} }
} }
File logs = new File(jenkins.getRootDir(), "logs"); File logs = getLogsRoot();
files = logs.listFiles(ROTATED_LOGFILE_FILTER); files = logs.listFiles(ROTATED_LOGFILE_FILTER);
if (files != null) { if (files != null) {
for (File f : files) { for (File f : files) {
Expand All @@ -128,6 +128,22 @@ private void addOtherMasterLogs(Container result) {
} }
} }


/**
* Returns the root directory for logs (historically always found under <code>$JENKINS_HOME/logs</code>.
* Configurable since Jenkins 2.114.
*
* @see hudson.triggers.SafeTimerTask#LOGS_ROOT_PATH_PROPERTY
* @return the root directory for logs.
*/
private File getLogsRoot() {
final String overriddenLogsRoot = System.getProperty("hudson.triggers.SafeTimerTask.logsTargetDir");
if (overriddenLogsRoot == null) {
return new File(Jenkins.get().getRootDir(), "logs");
} else {
return new File(overriddenLogsRoot);
}
}

/** /**
* Adds {@link Jenkins#logRecords} (from core) into the support bundle. * Adds {@link Jenkins#logRecords} (from core) into the support bundle.
* *
Expand Down

0 comments on commit 132c99f

Please sign in to comment.