11
11
public class OncePerMessageLoggingFilter implements LoggingFilter {
12
12
13
13
// allow all messages to be logged when filtering is off
14
- volatile boolean filtering = false ;
14
+ boolean filtering = false ;
15
15
16
16
Set messagesLogged = new HashSet ();
17
17
@@ -21,28 +21,24 @@ public class OncePerMessageLoggingFilter implements LoggingFilter {
21
21
*
22
22
* @param value true if filtering should be on, false if filtering should be off
23
23
*/
24
- public OncePerMessageLoggingFilter setFiltering (boolean value ) {
24
+ public synchronized OncePerMessageLoggingFilter setFiltering (boolean value ) {
25
25
filtering = value ;
26
26
return this ;
27
27
}
28
28
29
29
/** 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 ();
34
32
return this ;
35
33
}
36
34
37
35
@ 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 ;
46
40
}
41
+ messagesLogged .add (msg );
42
+ return true ;
47
43
}
48
44
}
0 commit comments