...10import java.util.logging.Level;11import java.util.logging.Logger;12import org.openqa.selenium.Beta;13import org.openqa.selenium.WebDriverException;14import org.openqa.selenium.logging.LocalLogs;15import org.openqa.selenium.logging.LogCombiner;16import org.openqa.selenium.logging.LogEntries;17import org.openqa.selenium.logging.LogEntry;18import org.openqa.selenium.logging.LogLevelMapping;19import org.openqa.selenium.logging.Logs;20@Beta21public class RemoteLogs22 implements Logs23{24 private static final String LEVEL = "level";25 private static final String TIMESTAMP = "timestamp";26 private static final String MESSAGE = "message";27 private static final Logger logger = Logger.getLogger(RemoteLogs.class.getName());28 protected ExecuteMethod executeMethod;29 @VisibleForTesting30 public static final String TYPE_KEY = "type";31 private final LocalLogs localLogs;32 33 public RemoteLogs(ExecuteMethod executeMethod, LocalLogs localLogs)34 {35 this.executeMethod = executeMethod;36 this.localLogs = localLogs;37 }38 39 public LogEntries get(String logType) {40 if ("profiler".equals(logType)) {41 LogEntries remoteEntries = new LogEntries(new ArrayList());42 try {43 remoteEntries = getRemoteEntries(logType);44 }45 catch (WebDriverException e)46 {47 logger.log(Level.WARNING, "Remote profiler logs are not available and have been omitted.", e);48 }49 50 return LogCombiner.combine(new LogEntries[] { remoteEntries, getLocalEntries(logType) });51 }52 if ("client".equals(logType)) {53 return getLocalEntries(logType);54 }55 return getRemoteEntries(logType);56 }57 58 private LogEntries getRemoteEntries(String logType) {59 Object raw = executeMethod.execute("getLog", ImmutableMap.of("type", logType));60 61 List<Map<String, Object>> rawList = (List)raw;62 List<LogEntry> remoteEntries = Lists.newArrayListWithCapacity(rawList.size());63 64 for (Map<String, Object> obj : rawList) {65 remoteEntries.add(new LogEntry(LogLevelMapping.toLevel((String)obj.get("level")), 66 ((Long)obj.get("timestamp")).longValue(), 67 (String)obj.get("message")));68 }69 return new LogEntries(remoteEntries);70 }71 72 private LogEntries getLocalEntries(String logType) {73 return localLogs.get(logType);74 }75 76 private Set<String> getAvailableLocalLogs() {77 return localLogs.getAvailableLogTypes();78 }79 80 public Set<String> getAvailableLogTypes() {81 Object raw = executeMethod.execute("getAvailableLogTypes", null);82 83 List<String> rawList = (List)raw;84 ImmutableSet.Builder<String> builder = new ImmutableSet.Builder();85 for (String logType : rawList) {86 builder.add(logType);87 }88 builder.addAll(getAvailableLocalLogs());89 return builder.build();90 }91}...