aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/RecentLogFilter.java
blob: 8b155864f33ebe7eed34db5a784b6ad7bf30f8bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model;

import java.util.LinkedList;
import java.util.logging.Filter;
import java.util.logging.LogRecord;

/**
 * A filter for log messages that prevents the most recently published messages
 * to be published again. See bug #461290.
 *
 * @author gjoranv
 */
public class RecentLogFilter implements Filter {

    LinkedList<String> recent = new LinkedList<>();
    static final int maxMessages = 6;

    public boolean isLoggable(LogRecord record) {
        String msg = record.getMessage();
        if (msg != null && recent.contains(msg)) {
            return false;  // duplicate
        } else {
            recent.addLast(msg);
            if (recent.size() > maxMessages) {
                recent.removeFirst();
            }
            return true;   // new message
        }
    }
}