i want to get the ADB logcats for a specific tag(ex: testing_aws) through APPIUM. actually i have done this directly from console like follows
adb shell logcat | grep testing_aws
which is successfully given the data as expectedList<LogEntry> adbLogs
=driver().manage().logs().get("logcat").filter(Level.ALL);
which it will give complete device logs, but i couldn't found a way to filter with specific tag (ex: testing_aws)You can first get all logs
List<LogEntry> logEntries = driver.manage().logs().get("logcat").filter(Level.ALL);
And then you can filter your log.
for (LogEntry logEntry : logEntries) {
if (logEntry.getMessage().contains("testing_aws")) {
System.out.println(logEntry.getMessage());
}
}
If you want to add the filtered log in the file, you can do it like following:
List<LogEntry> logEntries = driver.manage().logs().get("logcat").filter(Level.ALL);
File logFile = new File("path to store file"+"filename"+".txt");
logFile.getParentFile().mkdirs();
PrintWriter log_file_writer = new PrintWriter(logFile);
for (LogEntry logEntry : logEntries) {
if (logEntry.getMessage().contains("testing_aws")) {
log_file_writer.println(logEntry);
}
}
log_file_writer.flush();