Log4cpp源碼解析——Layut

一、功能描述

Layout 在Logcpp中實現日誌輸出格式的控制,組件接口如下所示

/**
 * Extend this abstract class to create your own log layout format.
 控制日誌的輸出格式
 **/
    class LOG4CPP_EXPORT Layout
    {
        public:
        /**
         * Destructor for Layout.
         **/
        virtual ~Layout() { };

        /**
         * Formats the LoggingEvent data to a string that appenders can log.
         * Implement this method to create your own layout format.
         * @param event The LoggingEvent.
         * @returns an appendable string.
         **/
        virtual std::string format(const LoggingEvent& event) = 0;
    };        

二、組價類圖如下圖所示,4種實現類完成了format 接口的具體實現

其中PatternLayout 中實現了多種定義好的輸出格式

 

 

發佈了28 篇原創文章 · 獲贊 3 · 訪問量 5982
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章