Jagadeesh
Jagadeesh

Reputation: 398

How to get ADB logcat with specific tag in appium?

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

Upvotes: 4

Views: 2766

Answers (1)

Suban Dhyako
Suban Dhyako

Reputation: 2526

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();

Upvotes: 2

Related Questions