import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class LogValidator {
public static void main(String[] args) {
List<String> logFiles = List.of("log1.txt", "log2.txt"); // Replace with your log file names
for (String logFile : logFiles) {
try {
validateLogFile(logFile);
} catch (IOException e) {
System.err.println("Error processing log file " + logFile + ": " + e.getMessage());
} catch (Exception e) {
System.err.println("Unexpected error processing log file " + logFile + ": " + e.getMessage());
}
}
}
public static void validateLogFile(String logFile) throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(logFile))) {
String line;
int lineNumber = 1;
boolean validationSuccessful = true;
while ((line = reader.readLine()) != null) {
// Perform your validation checks on each line here
if (!isValidLine(line)) {
System.err.println("Validation failed on line " + lineNumber + ": " + line);
validationSuccessful = false;
}
lineNumber++;
}
if (validationSuccessful) {
System.out.println("Log file " + logFile + " validation successful.");
} else {
System.err.println("Log file " + logFile + " validation failed.");
}
}
}
private static boolean isValidLine(String line) {
// Replace this with your actual validation logic
// This is just a placeholder example - check if line contains "ERROR"
return line.contains("ERROR");
}
}
Add your comment