Skip to content

Commit 5e6eefa

Browse files
committed
Prevent logging the same message multiple times in runKeyword
1 parent cb956fa commit 5e6eefa

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/main/java/JavaFXLibrary.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public Object runKeyword(String keywordName, Object[] args) {
8181
AtomicReference<RuntimeException> retExcep = new AtomicReference<>();
8282

8383
try {
84+
RobotLog.ignoreDuplicates();
8485
// timeout + 500 ms so that underlying timeout has a chance to expire first
8586
WaitForAsyncUtils.waitFor(getWaitUntilTimeout(TimeUnit.MILLISECONDS) + 500, TimeUnit.MILLISECONDS, () -> {
8687

@@ -100,6 +101,7 @@ public Object runKeyword(String keywordName, Object[] args) {
100101
}
101102
});
102103
} catch (TimeoutException te) {
104+
RobotLog.reset();
103105
RuntimeException e = retExcep.get();
104106
runOnFailure.runOnFailure();
105107

@@ -113,10 +115,12 @@ public Object runKeyword(String keywordName, Object[] args) {
113115
RobotLog.trace("JavaFXLibrary: Caught JavaFXLibrary RUNTIME exception: \n" + Throwables.getStackTraceAsString(e));
114116
throw e;
115117
}
116-
} catch (JavaFXLibraryTimeoutException jfxte){
118+
} catch (JavaFXLibraryTimeoutException jfxte) {
119+
RobotLog.reset();
117120
RobotLog.trace("JavaFXLibrary: Caught JavaFXLibrary TIMEOUT exception: \n" + Throwables.getStackTraceAsString(jfxte));
118121
throw jfxte;
119122
}
123+
RobotLog.reset();
120124
return retval.get();
121125
}
122126

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,57 @@
11
package javafxlibrary.utils;
22

3+
import java.util.LinkedList;
4+
35
public class RobotLog {
46

7+
private static boolean ignoreDuplicates = false;
8+
private static LinkedList<String> loggedMessages = new LinkedList<>();
9+
10+
11+
public static void ignoreDuplicates() {
12+
ignoreDuplicates = true;
13+
}
14+
15+
public static void reset() {
16+
ignoreDuplicates = false;
17+
loggedMessages.clear();
18+
}
19+
520
public static void info(String message) {
6-
System.out.println("*INFO* " + message);
21+
if (shouldLogMessage(message))
22+
System.out.println("*INFO* " + message);
723
}
824

925
public static void debug(String message) {
10-
System.out.println("*DEBUG* " + message);
26+
if (shouldLogMessage(message))
27+
System.out.println("*DEBUG* " + message);
1128
}
1229

1330
public static void trace(String message) {
14-
System.out.println("*TRACE* " + message);
31+
if (shouldLogMessage(message))
32+
System.out.println("*TRACE* " + message);
1533
}
1634

1735
public static void warn(String message) {
18-
System.out.println("*WARN* " + message);
36+
if (shouldLogMessage(message))
37+
System.out.println("*WARN* " + message);
1938
}
2039

2140
public static void error(String message) {
22-
System.out.println("*ERROR* " + message);
41+
if (shouldLogMessage(message))
42+
System.out.println("*ERROR* " + message);
43+
}
44+
45+
private static boolean shouldLogMessage(String message) {
46+
if (ignoreDuplicates) {
47+
if (loggedMessages.contains(message)) {
48+
return false;
49+
} else {
50+
loggedMessages.add(message);
51+
return true;
52+
}
53+
} else {
54+
return true;
55+
}
2356
}
2457
}

0 commit comments

Comments
 (0)