It's all about the answers!

Ask a question

How to download step's log on BF


qiu saphen (27126039) | asked Jun 13 '11, 11:02 a.m.
Hi,
My project is big and the core step output a great lot logs, every time I look at the log the browser will be blocked..so I want to download the step's logs and use editor to view.

Can I do that?

3 answers



permanent link
Brent Ulbricht (2.5k11) | answered Jun 13 '11, 11:56 a.m.
JAZZ DEVELOPER
Hi,
My project is big and the core step output a great lot logs, every time I look at the log the browser will be blocked..so I want to download the step's logs and use editor to view.

Can I do that?


Hi,

You can change the pagination on the step log page so that it shows only a certain amount of the log lines. The other thing you can do on the step log page is to select/unselect the types of log statements (ENV, etc.). However, for your question - one option is to create a script using the services layer API to get the logs from the result records for a build.

Brent Ulbricht
RTC Build Lead

permanent link
qiu saphen (27126039) | answered Jun 13 '11, 9:35 p.m.
Hi,
My project is big and the core step output a great lot logs, every time I look at the log the browser will be blocked..so I want to download the step's logs and use editor to view.

Can I do that?


Hi,

You can change the pagination on the step log page so that it shows only a certain amount of the log lines. The other thing you can do on the step log page is to select/unselect the types of log statements (ENV, etc.). However, for your question - one option is to create a script using the services layer API to get the logs from the result records for a build.

Brent Ulbricht
RTC Build Lead

Thanks for your suggestion. I think it's better to have the feature to let user download the logs for issue tracking.
Could you guide me where I can find the services layer API.

permanent link
Brent Ulbricht (2.5k11) | answered Jun 14 '11, 9:11 a.m.
JAZZ DEVELOPER
Hi,
My project is big and the core step output a great lot logs, every time I look at the log the browser will be blocked..so I want to download the step's logs and use editor to view.

Can I do that?


Hi,

You can change the pagination on the step log page so that it shows only a certain amount of the log lines. The other thing you can do on the step log page is to select/unselect the types of log statements (ENV, etc.). However, for your question - one option is to create a script using the services layer API to get the logs from the result records for a build.

Brent Ulbricht
RTC Build Lead

Thanks for your suggestion. I think it's better to have the feature to let user download the logs for issue tracking.
Could you guide me where I can find the services layer API.

You can retrieve the services layer clients by going to http://:/clients . You can select to download the Perl or Java client. I've attached some sample code for Java.


import com.buildforge.services.client.api.APIClientConnection;

import com.buildforge.services.client.dbo.Build;
import com.buildforge.services.client.dbo.Log;
import com.buildforge.services.client.dbo.Project;
import com.buildforge.services.client.dbo.Result;

import java.io.IOException;
import java.io.PrintWriter;

import java.util.ArrayList;
import java.util.List;

/**
* This is an example of using the services layer to
* retrieve log data.
*/
public class GetLogs {

private static final String TEST_PROJECT_NAME = "P_1";
private static final String LOG_FILE = "C:\\temp\\step_log_file.txt";

/**
* Since this is an example, the main method will do all the
* logic. Normally, this type of logic would be architected
* in a different way.
*
* @param args The command line arguments
* @throws Exception Any exceptions
*/
public static void main(String[] args) throws Exception {
APIClientConnection conn = new APIClientConnection("localhost", 3966);
conn.authUser("root", "root");

Project project = Project.findByName(conn, TEST_PROJECT_NAME);
if (project == null) {
throw new Exception("Could not find project named \"" + TEST_PROJECT_NAME + "\".");
}

List<Build> builds = Build.findByProjectUuid(conn, project.getUuid());
if (builds.size() <= 0) {
throw new Exception("Could not find any builds for project \"" + TEST_PROJECT_NAME + "\".");
}

Build build = builds.get(0);
List<Result> results = build.getResults();
if (results.size() <= 0) {
throw new Exception("Did not find any results for build with tag of \"" + build.getTag() + "\".");
}
PrintWriter writer = new PrintWriter(LOG_FILE);
writeToFile(writer, project.getName() + " - " + build.getTag());
for (Result result : results) {
writeToFile(writer, result.getDescription());
List<Log> logs = result.getLogs();
for (Log log : logs) {
writeToFile(writer, "\t" + log.getLineId() + "\t\t" + log.getType()
+ "\t\t\t" + log.getStamp() + "\t" + log.getMessageText());
}

}
writer.flush();
writer.close();
conn.logout();
conn.close();
}

/**
* A convenience method to write a line to the file
* and check for any errors.
*
* @param writer The writer used for writing to file
* @param line The line to write to the file
* @throws IOException If any problems writing to file
*/
private static void writeToFile(PrintWriter writer, String line) throws IOException {
writer.println(line);
if (writer.checkError()) {
throw new IOException();
}
}

}



Brent Ulbricht
RTC Build Lead

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.