File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed
src/org/openqa/selenium/logging
test/org/openqa/selenium/logging Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change 17
17
18
18
package org .openqa .selenium .logging ;
19
19
20
- import org .openqa .selenium .Beta ;
21
-
22
- import java .text .SimpleDateFormat ;
23
- import java .util .Date ;
20
+ import java .time .Instant ;
21
+ import java .time .format .DateTimeFormatter ;
24
22
import java .util .HashMap ;
25
23
import java .util .Map ;
26
24
import java .util .logging .Level ;
30
28
*/
31
29
public class LogEntry {
32
30
33
- private static final ThreadLocal <SimpleDateFormat > DATE_FORMAT =
34
- ThreadLocal .withInitial (() -> new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ssZ" ));
35
-
36
31
private final Level level ;
37
32
private final long timestamp ;
38
33
private final String message ;
@@ -77,11 +72,11 @@ public String getMessage() {
77
72
78
73
@ Override
79
74
public String toString () {
80
- return String .format ("[%s] [%s] %s" ,
81
- DATE_FORMAT .get ().format (new Date (timestamp )), level , message );
75
+ return String .format (
76
+ "[%s] [%s] %s" ,
77
+ DateTimeFormatter .ISO_INSTANT .format (Instant .ofEpochMilli (timestamp )), level , message );
82
78
}
83
79
84
- @ Beta
85
80
public Map <String , Object > toJson () {
86
81
Map <String , Object > map = new HashMap <>();
87
82
map .put ("timestamp" , timestamp );
Original file line number Diff line number Diff line change 28
28
29
29
import org .junit .Test ;
30
30
31
+ import java .util .Map ;
31
32
import java .util .logging .Level ;
32
33
33
34
public class LoggingTest {
@@ -54,4 +55,22 @@ public void canCompareLoggingPreferences() {
54
55
prefs2 .enable (LogType .BROWSER , Level .ALL );
55
56
assertThat (prefs2 ).isEqualTo (prefs1 );
56
57
}
58
+
59
+ @ Test
60
+ public void canRepresentLogEntryAsJson () {
61
+ long timestamp = 1572882588202L ;
62
+ LogEntry entry = new LogEntry (INFO , timestamp , "There is no more cheese" );
63
+ Map <String , Object > json = entry .toJson ();
64
+ assertThat (json )
65
+ .containsEntry ("timestamp" , timestamp )
66
+ .containsEntry ("level" , INFO )
67
+ .containsEntry ("message" , "There is no more cheese" );
68
+ }
69
+
70
+ @ Test
71
+ public void canRepresentLogEntryAsString () {
72
+ long timestamp = 1572882588202L ;
73
+ LogEntry entry = new LogEntry (INFO , timestamp , "There is no more cheese" );
74
+ assertThat (entry .toString ()).isEqualTo ("[2019-11-04T15:49:48.202Z] [INFO] There is no more cheese" );
75
+ }
57
76
}
You can’t perform that action at this time.
0 commit comments