FileSystemLogSaver

public class FileSystemLogSaver
extends Object implements ILogSaver

java.lang.Object
   ↳ com.android.tradefed.result.FileSystemLogSaver


Save logs to a file system.

Summary

Public constructors

FileSystemLogSaver()

Public methods

LogFile getLogReportDir()

Get the LogFile containing the path and/or URL of the directory where logs are saved.

void invocationEnded(long elapsedTime)

Reports that the invocation has terminated, whether successfully or due to some error condition.

void invocationStarted(IInvocationContext context)

Reports the start of the test invocation.

Also, create a unique file system directory under report-dir/[branch/]build-id/test-tag/unique_dir for saving logs.

LogFile saveLogData(String dataName, LogDataType dataType, InputStream dataStream)

Save the log data.

Will zip and save the log file if LogDataType.isCompressed() returns false for dataType and compressed-files is set, otherwise, the stream will be saved uncompressed.

LogFile saveLogFile(String dataName, LogDataType dataType, File fileToLog)

Save the log file.

void setCompressFiles(boolean compress)
void testModuleEnded()

Reports that the test module has terminated.

void testModuleStarted(IInvocationContext moduleContext)

Reports the start of the test module.

Protected methods

File createBuildDir(IBuildInfo buildInfo, File reportDir, String moduleName)

A helper method to get or create a build directory based on the build info of the invocation.

File generateLogReportDir(IBuildInfo buildInfo, File reportDir, String moduleName)

An exposed method that allow subclass to customize generating path logic.

Public constructors

FileSystemLogSaver

public FileSystemLogSaver ()

Public methods

getLogReportDir

public LogFile getLogReportDir ()

Get the LogFile containing the path and/or URL of the directory where logs are saved.

Returns
LogFile The LogFile.

invocationEnded

public void invocationEnded (long elapsedTime)

Reports that the invocation has terminated, whether successfully or due to some error condition.

Will be automatically called by the TradeFederation framework after ITestInvocationListener.invocationEnded(long) is called.

Parameters
elapsedTime long: the elapsed time of the invocation in ms

invocationStarted

public void invocationStarted (IInvocationContext context)

Reports the start of the test invocation.

Will be automatically called by the TradeFederation framework before ITestInvocationListener.invocationStarted(IInvocationContext) is called.

Also, create a unique file system directory under report-dir/[branch/]build-id/test-tag/unique_dir for saving logs. If the creation of the directory fails, will write logs to a temporary directory on the local file system.

Parameters
context IInvocationContext: information about the invocation.

saveLogData

public LogFile saveLogData (String dataName, 
                LogDataType dataType, 
                InputStream dataStream)

Save the log data.

Will be automatically called by the TradeFederation framework whenever ITestInvocationListener.testLog(String,LogDataType,InputStreamSource) is called. It may also be used as a helper method to save additional log data.

Depending on the implementation and policy, the logs may be saved in a compressed form. Logs may also be stored in a location inaccessible to Tradefed.

Will zip and save the log file if LogDataType.isCompressed() returns false for dataType and compressed-files is set, otherwise, the stream will be saved uncompressed.

Parameters
dataName String: a String descriptive name of the data. e.g. "device_logcat"

dataType LogDataType: the LogDataType of the file.

dataStream InputStream: the InputStream of the data.

Returns
LogFile the LogFile containing the path and URL of the saved file.

Throws
IOException

saveLogFile

public LogFile saveLogFile (String dataName, 
                LogDataType dataType, 
                File fileToLog)

Save the log file.

Will be automatically called by the TradeFederation framework whenever ITestInvocationListener.testLog(String,LogDataType,InputStreamSource) is called and the stream references a file.

Depending on the implementation and policy, the logs may be saved in a compressed form. Logs may also be stored in a location inaccessible to Tradefed.

Parameters
dataName String: a String descriptive name of the data. e.g. "device_logcat"

dataType LogDataType: the LogDataType of the file.

fileToLog File: the File to save.

Returns
LogFile the LogFile containing the path and URL of the saved file.

Throws
IOException

setCompressFiles

public void setCompressFiles (boolean compress)

Parameters
compress boolean

testModuleEnded

public void testModuleEnded ()

Reports that the test module has terminated.

testModuleStarted

public void testModuleStarted (IInvocationContext moduleContext)

Reports the start of the test module.

Parameters
moduleContext IInvocationContext: information about the module.

Protected methods

createBuildDir

protected File createBuildDir (IBuildInfo buildInfo, 
                File reportDir, 
                String moduleName)

A helper method to get or create a build directory based on the build info of the invocation.

Create a unique file system directory with the structure report-dir/[branch/]build-id/test-tag for saving logs.

Parameters
buildInfo IBuildInfo: the IBuildInfo

reportDir File: the File for the report directory.

moduleName String: the name for the test module

Returns
File The directory where invocations for the same build should be saved.

Throws
IOException if the directory could not be created because a file with the same name exists or there are no permissions to write to it.

generateLogReportDir

protected File generateLogReportDir (IBuildInfo buildInfo, 
                File reportDir, 
                String moduleName)

An exposed method that allow subclass to customize generating path logic.

Parameters
buildInfo IBuildInfo: the IBuildInfo

reportDir File: the File for the report directory.

moduleName String: the name for the test module

Returns
File The directory created.

Throws
IOException