Class BuildLogFileAccessor
java.lang.Object
com.atlassian.bamboo.build.logger.BuildLogFileAccessor
This class provides a mechanism to perform operations on build/deployment log files.
An accessor class must be instantiated for each build log file.
Other notes:
When using the file iterator, it is not thread safe.
Be sure to open the file for iteration and close it once you are done.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close the file iteratorgetLastNLogs
(int numLogs) Retrives a List of the last N logs.getLastNLogsOfType
(int numLogs, Collection<Class<?>> types) int
Counts the number of lines in the file.int
getNumberOfLinesOfType
(Collection<Class<?>> types) Counts the number of lines in the log file, only taking into account log entries of specified types.boolean
hasNext()
Requires file to be opened for iteration@Nullable String
nextLine()
Requires file to be opened for iteration@Nullable LogEntry
Requires file to be opened for iterationboolean
Open the file contained within this accessor to perform iterations (must be called before the hasNext(), nextLogEntry() and nextLine()).@Nullable LogEntry
searchFileForEntry
(@Nullable String textToSearchFor, boolean searchInErrorMessages) Looks incrementally through the file to see if the specified text exists@Nullable LogEntry
searchFileForEntry
(@Nullable String textToSearchFor, int lastNLines, boolean searchInErrorMessages) Searchers for particular text within the last n lines of a file (eg search within the last 10 lines for a success message)
-
Field Details
-
ENCODING
- See Also:
-
-
Method Details
-
openFileForIteration
public boolean openFileForIteration()Open the file contained within this accessor to perform iterations (must be called before the hasNext(), nextLogEntry() and nextLine()).- Returns:
- true if the opening of the file was successful, otherwise false.
-
closeFileForIteration
public void closeFileForIteration()close the file iterator -
hasNext
public boolean hasNext()Requires file to be opened for iteration- Returns:
- true if there is another line in the file, otherwise false
-
nextLogEntry
Requires file to be opened for iteration- Returns:
- The next line in the file as a LogEntry, null if no more lines
-
nextLine
Requires file to be opened for iteration- Returns:
- The next line in the file as a String, null if no more lines
-
searchFileForEntry
@Nullable public @Nullable LogEntry searchFileForEntry(@Nullable @Nullable String textToSearchFor, boolean searchInErrorMessages) throws IOException Looks incrementally through the file to see if the specified text exists- Parameters:
textToSearchFor
- the specific text to search forsearchInErrorMessages
- search also in error messages- Returns:
- the LogEntry that the text was found in or null if the text was not found
- Throws:
IOException
- if there were errors accessing the file
-
searchFileForEntry
@Nullable public @Nullable LogEntry searchFileForEntry(@Nullable @Nullable String textToSearchFor, int lastNLines, boolean searchInErrorMessages) throws IOException Searchers for particular text within the last n lines of a file (eg search within the last 10 lines for a success message)- Parameters:
textToSearchFor
- String text to find in filelastNLines
- number of lines from end to search fromsearchInErrorMessages
- search also in error messages- Returns:
- the LogEntry the text was found in or null if the text was not found
- Throws:
IOException
- if error closing the log file
-
getLastNLogs
Retrives a List of the last N logs. Avoid using this with large numbers as it has the potential to cause out of memory errors- Parameters:
numLogs
- number of logs to retrieve- Returns:
- List of the last N LogEntry Objects in the file, may return an empty list
- Throws:
IOException
- if errors access the build log file
-
getLastNLogsOfType
public List<LogEntry> getLastNLogsOfType(int numLogs, Collection<Class<?>> types) throws IOException - Throws:
IOException
-
getNumberOfLinesInFile
Counts the number of lines in the file.- Returns:
- number of lines in file
- Throws:
IOException
- if errors accessing the file
-
getNumberOfLinesOfType
Counts the number of lines in the log file, only taking into account log entries of specified types. More general types will include number of log entries for more specific types (e.g. querying forSimpleLogEntry
will also include log count for typesCommandLogEntry
orErrorLogEntry
)- Parameters:
types
- types of log entries for which to calculate result- Returns:
- number of log entries of given types
- Throws:
IOException
- if errors occur while accessing the log file
-