Log files

Log files are also used frequently in testing to verify entries in server logs, application logs, and browser logs. Static utility methods can be built to extract log data as well. Here is a simple example:

/**
* extractData_LOG - method to extract Log file data for use in testing
*
* @param logFile - the logfile to read
* @return List<String>
* @throws Exception
*/
public static List<String> extractData_LOG(String logFile)
throws IOException {
List<String> rows = new ArrayList<String>();

BufferedReader reader = new BufferedReader(new FileReader(logFile));
String line = "";

while
( (line = reader.readLine()) != null ) {
rows.add(line);
}

reader.close();
return rows;
}
/**
* writeFile - method to stuff a row entry into a file
*
* @param file - the file to write to
* @param rowData - the line to write into the file

* @throws Exception
*/
public static void writeFile(String file,
String rowData)
throws Exception {

Boolean bFound = false;

BufferedReader reader = new BufferedReader(new FileReader(file));
String getLine = "";

// verify if row entry exists
while ( (getLine = reader.readLine()) != null ) {
if ( getLine.contains(rowData)) {
bFound = true;
break;
}
}

reader.close();

if
( bFound != true ) {
BufferedWriter writer =
new BufferedWriter(new FileWriter(file, true));

writer.append(rowData);
writer.newLine();
writer.close();
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.172.68