| 28 | import org.openqa.selenium.json.JsonInput; |
| 29 | |
| 30 | public class v156Log implements org.openqa.selenium.devtools.idealized.log.Log { |
| 31 | |
| 32 | @Override |
| 33 | public Command<Void> enable() { |
| 34 | return Log.enable(); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public Command<Void> clear() { |
| 39 | return Log.clear(); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public Event<org.openqa.selenium.devtools.idealized.log.model.LogEntry> entryAdded() { |
| 44 | return new Event<>( |
| 45 | Log.entryAdded().getMethod(), |
| 46 | input -> { |
| 47 | Function<JsonInput, LogEntry> mapper = ConverterFunctions.map("entry", LogEntry.class); |
| 48 | LogEntry entry = mapper.apply(input); |
| 49 | |
| 50 | return new org.openqa.selenium.devtools.idealized.log.model.LogEntry( |
| 51 | entry.getSource().toString(), |
| 52 | new org.openqa.selenium.logging.LogEntry( |
| 53 | fromCdpLevel(entry.getLevel()), |
| 54 | fromCdpTimestamp(entry.getTimestamp()), |
| 55 | entry.getText())); |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | private Level fromCdpLevel(LogEntry.Level level) { |
| 60 | switch (level.toString()) { |
| 61 | case "verbose": |
| 62 | return Level.FINEST; |
| 63 | |
| 64 | case "info": |
| 65 | return Level.INFO; |
| 66 | |
| 67 | case "warning": |
| 68 | return Level.WARNING; |
| 69 | |
| 70 | case "error": |
| 71 | return Level.SEVERE; |
| 72 | |
| 73 | default: |
| 74 | return Level.INFO; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | private long fromCdpTimestamp(Timestamp timestamp) { |
| 79 | try { |
| 80 | return Long.parseLong(timestamp.toString()); |
| 81 | } catch (NumberFormatException e) { |
| 82 | return System.currentTimeMillis(); |
| 83 | } |
| 84 | } |
| 85 | } |
nothing calls this directly
no outgoing calls
no test coverage detected