Skip to content

Commit 99e9c70

Browse files
committed
use same lock for both filtering and messagesLogged
1 parent 2d15731 commit 99e9c70

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

operator/src/main/java/oracle/kubernetes/operator/logging/OncePerMessageLoggingFilter.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class OncePerMessageLoggingFilter implements LoggingFilter {
1212

1313
// allow all messages to be logged when filtering is off
14-
volatile boolean filtering = false;
14+
boolean filtering = false;
1515

1616
Set messagesLogged = new HashSet();
1717

@@ -21,28 +21,24 @@ public class OncePerMessageLoggingFilter implements LoggingFilter {
2121
*
2222
* @param value true if filtering should be on, false if filtering should be off
2323
*/
24-
public OncePerMessageLoggingFilter setFiltering(boolean value) {
24+
public synchronized OncePerMessageLoggingFilter setFiltering(boolean value) {
2525
filtering = value;
2626
return this;
2727
}
2828

2929
/** Clears the list of history of messages logged and turn off filtering */
30-
public OncePerMessageLoggingFilter resetLogHistory() {
31-
synchronized (messagesLogged) {
32-
messagesLogged.clear();
33-
}
30+
public synchronized OncePerMessageLoggingFilter resetLogHistory() {
31+
messagesLogged.clear();
3432
return this;
3533
}
3634

3735
@Override
38-
public boolean canLog(String msg) {
39-
synchronized (messagesLogged) {
40-
// Do not log if filtering is on and message has already been logged
41-
if (filtering && messagesLogged.contains(msg)) {
42-
return false;
43-
}
44-
messagesLogged.add(msg);
45-
return true;
36+
public synchronized boolean canLog(String msg) {
37+
// Do not log if filtering is on and message has already been logged
38+
if (filtering && messagesLogged.contains(msg)) {
39+
return false;
4640
}
41+
messagesLogged.add(msg);
42+
return true;
4743
}
4844
}

0 commit comments

Comments
 (0)