to top
public class

LogFileSaver

extends Object
java.lang.Object
   ↳ com.android.tradefed.result.LogFileSaver

Class Overview

A helper for ITestInvocationListener's that will save log data to a file

Summary

Public Constructors
LogFileSaver(IBuildInfo buildInfo, File rootDir, Integer logRetentionDays)
Creates a LogFileSaver.
LogFileSaver(IBuildInfo buildInfo, File rootDir)
Creates a LogFileSaver.
LogFileSaver(File rootDir)
An alternate LogFileSaver constructor that will just use given directory as the log storage directory.
Public Methods
File createCompressedLogFile(String dataName, LogDataType origDataType, LogDataType compressedType)
Creates an empty file for storing compressed log data.
OutputStream createGZipLogStream(File logFile)
Creates a output stream to write GZIP-compressed data to a file
InputStream createInputStreamFromFile(File logFile)
Helper method to create an input stream to read contents of given log fi

TODO: consider moving this method elsewhere.

File getFileDir()
Get the directory used to store files.
File saveAndZipLogData(String dataName, LogDataType dataType, InputStream dataStream)
Save and compress, if necessary, the log data to a zip file
File saveLogData(String dataName, LogDataType dataType, InputStream dataStream)
Save the log data to a file
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public LogFileSaver (IBuildInfo buildInfo, File rootDir, Integer logRetentionDays)

Creates a LogFileSaver.

Construct a unique file system directory in rootDir/branch/build_id/testTag/uniqueDir

If directory creation fails, will use a temp directory.

Parameters
buildInfo IBuildInfo: the IBuildInfo
rootDir File: the root file system path
logRetentionDays Integer: If provided a '.retention' file will be written to log directory containing a timestamp equal to current time + logRetentionDays. External cleanup scripts can use this file to determine when to delete log directories.

public LogFileSaver (IBuildInfo buildInfo, File rootDir)

Creates a LogFileSaver.

Construct a unique file system directory in rootDir/branch/build_id/uniqueDir

Parameters
buildInfo IBuildInfo: the IBuildInfo
rootDir File: the root file system path

public LogFileSaver (File rootDir)

An alternate LogFileSaver constructor that will just use given directory as the log storage directory.

Public Methods

public File createCompressedLogFile (String dataName, LogDataType origDataType, LogDataType compressedType)

Creates an empty file for storing compressed log data.

Parameters
dataName String: a String descriptive name of the data to be stor "device_logcat"
origDataType LogDataType: the type of LogDataType to be stored
compressedType LogDataType: the LogDataType representing the compressi GZIP or ZIP
Returns
File a File
Throws
IOException if log file could not be created

public OutputStream createGZipLogStream (File logFile)

Creates a output stream to write GZIP-compressed data to a file

Parameters
logFile File
Returns
OutputStream the OutputStream to compress and write data to the file. this stream when complete
Throws
IOException if stream could not be generated

public InputStream createInputStreamFromFile (File logFile)

Helper method to create an input stream to read contents of given log fi

TODO: consider moving this method elsewhere. Placed here for now so it e users of this class to mock.

Parameters
logFile File: the File to read from
Returns
InputStream a buffered InputStream to read file data. Callers must c this stream when complete
Throws
IOException if stream could not be generated

public File getFileDir ()

Get the directory used to store files.

Returns
File the File directory

public File saveAndZipLogData (String dataName, LogDataType dataType, InputStream dataStream)

Save and compress, if necessary, the log data to a zip file

Parameters
dataName String: a String descriptive name of the data. e.g. "dev
dataType LogDataType: the LogDataType of the file. Log data which is a (ie isCompressed() is true)
dataStream InputStream: the InputStream of the data.
Returns
File the file of the generated data
Throws
IOException if log file could not be generated

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

Save the log data to a file

Parameters
dataName String: a String descriptive name of the data. e.g. "dev
dataType LogDataType: the LogDataType of the file.
dataStream InputStream: the InputStream of the data.
Returns
File the file of the generated data
Throws
IOException if log file could not be generated