Use:
List<LogEntry> logEntries = driver.manage().logs().get("logcat").filter(Level.ALL);
You can change filter level by your need. The problem is that all log entries are written in the same line, so I made a function that puts each log entry into new line:
private List<LogEntry> orderLogEntries(List<LogEntry> oldEntries) {
List<LogEntry> newEntries = new ArrayList<>();
LogEntry tempEntry;
for (LogEntry entry : oldEntries) {
tempEntry = new LogEntry(entry.getLevel(), entry.getTimestamp(), entry.getMessage() + "\n");
newEntries.add(tempEntry);
}
return newEntries;
}
… , then I save it to file. If you need to get specific log entry, you will need to parse it out. Maybe help yourself with
entry.getMessage()