Starting March 27, 2025, we recommend using android-latest-release instead of aosp-main to build and contribute to AOSP. For more information, see Changes to AOSP.
         
       
     
  
  
  
  
  
    
    
      
    
    
      
      Stay organized with collections
    
    
      
      Save and categorize content based on your preferences.
    
  
  
    
  
  
  
  
    
  
  
    
    
  
  
LogFileSaver
  public
  
  
  
  class
  LogFileSaver
  
    extends Object
  
  
  
  
  
  
  
    
    | java.lang.Object | 
  
  
    
      | ↳ | com.android.tradefed.result.LogFileSaver | 
  
  
    
  A helper for ITestInvocationListener's that will save log data to a file
Summary
| Public methods | 
|---|
  
  
  
    | 
        
        
        
        
        
        File | 
      createCompressedLogFile(String dataName, LogDataType origDataType)
      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.
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
         | 
      getInvocationLogPathSegments()
       | 
  
  
  
  
    | 
        
        
        
        
        
        File | 
      saveAndGZipLogData(String dataName, LogDataType dataType, InputStream dataStream)
      Save and compress, if necessary, the log data to a gzip file
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        File | 
      saveAndGZipLogFile(String dataName, LogDataType dataType, File fileToLog)
      Save and compress, if necessary, the log data to a gzip file
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        File | 
      saveLogData(String dataName, LogDataType dataType, InputStream dataStream)
      Save the log data to a file
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        File | 
      saveLogDataRaw(String dataName, String ext, InputStream dataStream)
      Save raw data to a file
        
    
 | 
  
  
  
  
    | 
        
        
        
        
        
        File | 
      saveLogFile(String dataName, LogDataType dataType, File fileToLog)
      Save a given log file
        
    
 | 
  
Public constructors
    LogFileSaver
    
public LogFileSaver (IBuildInfo buildInfo, 
                File rootDir)
    
    
    
  Creates a LogFileSaver.
 
 Construct a unique file system directory in rootDir/branch/build_id/uniqueDir
    
    | Parameters | 
|---|
      
        | buildInfo | IBuildInfo: theIBuildInfo | 
      
        | rootDir | File: the root file system path | 
    
 
    LogFileSaver
    
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: theIBuildInfo | 
      
        | 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. | 
    
 
    LogFileSaver
    
public LogFileSaver (File rootDir)
    
    
    
  An alternate LogFileSaver constructor that will just use given directory as the
 log storage directory.
 
Public methods
    createCompressedLogFile
    
public File createCompressedLogFile (String dataName, 
                LogDataType origDataType)
    
    
    
  Creates an empty file for storing compressed log data.
    
    | Parameters | 
|---|
      
        | dataName | String: aStringdescriptive name of the data to be stored. | 
      
        | origDataType | LogDataType: the type ofLogDataTypeto be stored | 
    
    
      
      | Throws | 
|---|
        
          |  | if log file could not be created | 
      
  
 
    createGZipLogStream
    
public OutputStream createGZipLogStream (File logFile)
    
    
    
  Creates a output stream to write GZIP-compressed data to a file
    
    
      | Returns | 
|---|
      
        | OutputStream | the ERROR(/OutputStream)to compress and write data to the file.
         this stream when complete | 
    
      
      | Throws | 
|---|
        
          |  | 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.
    
    
      | Returns | 
|---|
      
        | InputStream | a buffered ERROR(/InputStream)to read file data. Callers must call
         this stream when complete | 
    
      
      | Throws | 
|---|
        
          |  | if stream could not be generated | 
      
  
 
    getFileDir
    
public File getFileDir ()
    
    
    
  Get the directory used to store files.
    
 
    getInvocationLogPathSegments
    
public  getInvocationLogPathSegments ()
    
    
    
  
    
      | Returns | 
|---|
      
        |  | the unique invocation log path segments. | 
    
 
    
    
public File saveAndGZipLogData (String dataName, 
                LogDataType dataType, 
                InputStream dataStream)
    
    
    
  Save and compress, if necessary, the log data to a gzip file
    
    
      | Returns | 
|---|
      
        | File | the file of the generated data | 
    
      
      | Throws | 
|---|
        
          |  | if log file could not be generated | 
      
  
 
    saveAndGZipLogFile
    
public File saveAndGZipLogFile (String dataName, 
                LogDataType dataType, 
                File fileToLog)
    
    
    
  Save and compress, if necessary, the log data to a gzip file
    
    
      | Returns | 
|---|
      
        | File | the file of the generated data | 
    
      
      | Throws | 
|---|
        
          |  | if log file could not be generated | 
      
  
 
    
    
public File saveLogData (String dataName, 
                LogDataType dataType, 
                InputStream dataStream)
    
    
    
  Save the log data to a file
    
    
      | Returns | 
|---|
      
        | File | the file of the generated data | 
    
      
      | Throws | 
|---|
        
          |  | if log file could not be generated | 
      
  
 
    
    
public File saveLogDataRaw (String dataName, 
                String ext, 
                InputStream dataStream)
    
    
    
  Save raw data to a file
    
    | Parameters | 
|---|
      
        | dataName | String: aStringdescriptive name of the data. | 
      
        | ext | String: the extension of the date | 
      
        | dataStream | InputStream: theERROR(/InputStream)of the data. | 
    
    
      | Returns | 
|---|
      
        | File | the file of the generated data | 
    
      
      | Throws | 
|---|
        
          |  | if log file could not be generated | 
      
  
 
    saveLogFile
    
public File saveLogFile (String dataName, 
                LogDataType dataType, 
                File fileToLog)
    
    
    
  Save a given log file
    
    | Parameters | 
|---|
      
        | dataName | String: aStringdescriptive name of the data. | 
      
        | dataType | LogDataType: theLogDataTypeof the file. | 
      
        | fileToLog | File: theERROR(/File)to be logged | 
    
    
      | Returns | 
|---|
      
        | File | the file of the generated data | 
    
      
      | Throws | 
|---|
        
          |  | if log file could not be generated | 
      
  
 
 
 
  
  
 
  
    
    
      
    
    
  
       
    
    
  
  
  Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
  Last updated 2024-12-09 UTC.
  
  
  
    
      [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-09 UTC."],[],[]]