最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

logback的DuplicateMessageFilter日志過濾操作源碼解讀

 更新時間:2023年11月13日 09:50:15   作者:codecraft  
這篇文章主要為大家介紹了logback的DuplicateMessageFilter日志過濾操作源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

本文主要研究一下logback的DuplicateMessageFilter

TurboFilter

ch/qos/logback/classic/turbo/TurboFilter.java

public abstract class TurboFilter extends ContextAwareBase implements LifeCycle {
    private String name;
    boolean start = false;
    /**
     * Make a decision based on the multiple parameters passed as arguments. The
     * returned value should be one of <code>{@link FilterReply#DENY}</code>,
     * <code>{@link FilterReply#NEUTRAL}</code>, or
     * <code>{@link FilterReply#ACCEPT}</code>.
     * 
     * @param marker
     * @param logger
     * @param level
     * @param format
     * @param params
     * @param t
     * @return
     */
    public abstract FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params,
            Throwable t);
    public void start() {
        this.start = true;
    }
    public boolean isStarted() {
        return this.start;
    }
    public void stop() {
        this.start = false;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
TurboFilter繼承了ContextAwareBase,聲明實現(xiàn)LifeCycle接口,它定義了decide方法由子類實現(xiàn)

DuplicateMessageFilter

ch/qos/logback/classic/turbo/DuplicateMessageFilter.java

public class DuplicateMessageFilter extends TurboFilter {
    /**
     * The default cache size.
     */
    public static final int DEFAULT_CACHE_SIZE = 100;
    /**
     * The default number of allows repetitions.
     */
    public static final int DEFAULT_ALLOWED_REPETITIONS = 5;
    public int allowedRepetitions = DEFAULT_ALLOWED_REPETITIONS;
    public int cacheSize = DEFAULT_CACHE_SIZE;
    private LRUMessageCache msgCache;
    @Override
    public void start() {
        msgCache = new LRUMessageCache(cacheSize);
        super.start();
    }
    @Override
    public void stop() {
        msgCache.clear();
        msgCache = null;
        super.stop();
    }
    @Override
    public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
        int count = msgCache.getMessageCountAndThenIncrement(format);
        if (count <= allowedRepetitions) {
            return FilterReply.NEUTRAL;
        } else {
            return FilterReply.DENY;
        }
    }
    public int getAllowedRepetitions() {
        return allowedRepetitions;
    }
    /**
     * The allowed number of repetitions before
     * 
     * @param allowedRepetitions
     */
    public void setAllowedRepetitions(int allowedRepetitions) {
        this.allowedRepetitions = allowedRepetitions;
    }
    public int getCacheSize() {
        return cacheSize;
    }
    public void setCacheSize(int cacheSize) {
        this.cacheSize = cacheSize;
    }
}
DuplicateMessageFilter繼承了TurboFilter,它使用了LRUMessageCache(默認大小100)來緩存format,decide方法會執(zhí)行g(shù)etMessageCountAndThenIncrement,若超出allowedRepetitions(默認5)則返回FilterReply.DENY,否則返回FilterReply.NEUTRAL

LRUMessageCache

ch/qos/logback/classic/turbo/LRUMessageCache.java

class LRUMessageCache extends LinkedHashMap<String, Integer> {
    private static final long serialVersionUID = 1L;
    final int cacheSize;
    LRUMessageCache(int cacheSize) {
        super((int) (cacheSize * (4.0f / 3)), 0.75f, true);
        if (cacheSize < 1) {
            throw new IllegalArgumentException("Cache size cannot be smaller than 1");
        }
        this.cacheSize = cacheSize;
    }
    int getMessageCountAndThenIncrement(String msg) {
        // don't insert null elements
        if (msg == null) {
            return 0;
        }
        Integer i;
        // LinkedHashMap is not LinkedHashMap. See also LBCLASSIC-255
        synchronized (this) {
            i = super.get(msg);
            if (i == null) {
                i = 0;
            } else {
                i = i + 1;
            }
            super.put(msg, i);
        }
        return i;
    }
    // called indirectly by get() or put() which are already supposed to be
    // called from within a synchronized block
    protected boolean removeEldestEntry(Map.Entry<String, Integer> eldest) {
        return (size() > cacheSize);
    }
    @Override
    synchronized public void clear() {
        super.clear();
    }
}
LRUMessageCache繼承了LinkedHashMap,其初始size為cacheSize * (4.0f / 3),getMessageCountAndThenIncrement方法內(nèi)部通過synchronized加鎖獲取指定msg的次數(shù),不存在則設(shè)置為0,存在則遞增;其removeEldestEntry方法判斷size() > cacheSize

小結(jié)

DuplicateMessageFilter繼承了TurboFilter,它使用了LRUMessageCache(默認大小100)來緩存format,decide方法會執(zhí)行g(shù)etMessageCountAndThenIncrement,若超出allowedRepetitions(默認5)則返回FilterReply.DENY,否則返回FilterReply.NEUTRAL。

以上就是logback的DuplicateMessageFilter的詳細內(nèi)容,更多關(guān)于logback的DuplicateMessageFilter的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Java服務(wù)如何調(diào)用系統(tǒng)指令、Bat腳本記錄

    Java服務(wù)如何調(diào)用系統(tǒng)指令、Bat腳本記錄

    這篇文章主要介紹了Java服務(wù)如何調(diào)用系統(tǒng)指令、Bat腳本記錄,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • Spring中的Devtools源碼解析

    Spring中的Devtools源碼解析

    這篇文章主要介紹了Spring中的Devtools源碼解析,Spring中的Devtools是一個開發(fā)工具,旨在提高開發(fā)人員的生產(chǎn)力和開發(fā)體驗,它提供了一系列功能,包括自動重啟、熱部署、遠程調(diào)試等,使開發(fā)人員能夠更快速地進行代碼修改和調(diào)試,需要的朋友可以參考下
    2023-10-10
  • Java ArrayList的底層實現(xiàn)方法

    Java ArrayList的底層實現(xiàn)方法

    今天小編就為大家分享一篇Java ArrayList的底層實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • Spring Boot集成教程之異步調(diào)用Async

    Spring Boot集成教程之異步調(diào)用Async

    在項目中,當訪問其他人的接口較慢或者做耗時任務(wù)時,不想程序一直卡在耗時任務(wù)上,想程序能夠并行執(zhí)行,我們可以使用多線程來并行的處理任務(wù),也可以使用spring提供的異步處理方式@Async。需要的朋友們下面來一起看看吧。
    2018-03-03
  • 詳解application.properties和application.yml文件的區(qū)別

    詳解application.properties和application.yml文件的區(qū)別

    這篇文章主要介紹了詳解application.properties和application.yml文件的區(qū)別,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • Netty如何自定義編碼解碼器

    Netty如何自定義編碼解碼器

    Netty自定義編碼解碼器:InboundHandler處理入棧數(shù)據(jù),OutboundHandler處理出棧數(shù)據(jù),解碼器繼承ByteToMessageDecoder,編碼器繼承MessageToByteEncoder,ReplayingDecoder簡化了解碼邏輯,但可能因異常重試導致性能下降
    2025-03-03
  • 使用MultipartFile來上傳單個及多個文件代碼示例

    使用MultipartFile來上傳單個及多個文件代碼示例

    這篇文章主要介紹了使用MultipartFile來上傳單個及多個文件代碼示例,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • 淺談web服務(wù)器項目中靜態(tài)請求和動態(tài)請求處理

    淺談web服務(wù)器項目中靜態(tài)請求和動態(tài)請求處理

    這篇文章主要介紹了淺談web服務(wù)器項目中靜態(tài)請求和動態(tài)請求處理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-07-07
  • java實現(xiàn)文件重命名

    java實現(xiàn)文件重命名

    這篇文章主要為大家詳細介紹了java實現(xiàn)文件重命名,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • springBoot啟動輸出三行日志控制臺自動停止操作

    springBoot啟動輸出三行日志控制臺自動停止操作

    這篇文章主要介紹了springBoot啟動輸出三行日志控制臺自動停止操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08

最新評論

阳高县| 安岳县| 江城| 保德县| 深圳市| 黄冈市| 荣成市| 葵青区| 彭泽县| 台南市| 黑山县| 旌德县| 铜梁县| 满城县| 淄博市| 郴州市| 大渡口区| 通化市| 新沂市| 绥滨县| 南陵县| 明水县| 仙居县| 平顺县| 华宁县| 当阳市| 曲松县| 津市市| 苏尼特左旗| 石台县| 聊城市| 诸城市| 沂南县| 侯马市| 英山县| 乌鲁木齐市| 岑巩县| 广宗县| 怀宁县| 那坡县| 新巴尔虎右旗|