If you are using TestNG, you can just throw an exception.
TestNG will capture the exception and mark the test as a fail.
Something like this for example.
public void analyzeBrowserLogs() {
String type = "browser";
List<LogEntry> entries = driver.manage().logs().get(type).getAll();
System.out.println(entries.size() + " " + type + " log entries found");
for (LogEntry entry : entries) {
if(entry.getMessage().contains("SEVERE")){
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
throw new Exception(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
}
}
}
Make sure not to use function analyzeBrowserLogs() inside try-catch block or function that is using the function analyzeBrowserLogs inside a try-catch block.