C++ windows LOG4plus的使用小結(jié)
下載源碼
下載后再對應(yīng)的目錄下打開.sln文件
本次編譯的是這個項目
新建一個項目
項目在test目錄中
將頭文件和lib如下添加
在項目中配置
注意源碼編譯的動態(tài)庫的字符集和測試程序的字符集要一致,不然會報錯
#include <log4cplus/logger.h> #include <log4cplus/fileappender.h> #include <log4cplus/layout.h> #include <log4cplus/ndc.h> #include <log4cplus/helpers/loglog.h> #include <log4cplus/loggingmacros.h> #include <log4cplus/consoleappender.h> #include <log4cplus/loggingmacros.h> #include <log4cplus/configurator.h> using namespace log4cplus; int main() { log4cplus::initialize(); // // 從配置文件加載配置 PropertyConfigurator::doConfigure("log4cplus.properties"); log4cplus::Logger logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("example")); LOG4CPLUS_DEBUG(logger,"Entering loop #" ); return 0; }
配置文件 log4cplus.properties 配置
# 設(shè)置根日志級別為DEBUG log4cplus.rootLogger=DEBUG, FILE # 文件輸出 log4cplus.appender.FILE=log4cplus::RollingFileAppender log4cplus.appender.FILE.File=logs/mylog.log log4cplus.appender.FILE.MaxFileSize=10MB log4cplus.appender.FILE.MaxBackupIndex=5 log4cplus.appender.FILE.layout=log4cplus::PatternLayout log4cplus.appender.FILE.layout.ConversionPattern=%d{%Y-%m-%d %H:%M:%S.%q} [%t] %-5p %c - %m%n # 控制臺輸出 log4cplus.appender.STDOUT=log4cplus::ConsoleAppender log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout log4cplus.appender.STDOUT.layout.ConversionPattern=%d{%Y-%m-%d %H:%M:%S.%q} [%t] %-5p %c - %m%n
代碼
https://github.com/zzlongbin/Log4Plus.git
到此這篇關(guān)于C++ windows LOG4plus的使用的文章就介紹到這了,更多相關(guān)C++ windows LOG4plus內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++中的類成員函數(shù)當(dāng)線程函數(shù)
這篇文章主要介紹了C++中的類成員函數(shù)當(dāng)線程函數(shù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-11-11typedef和#define用法區(qū)別總結(jié)
在C還是C++代碼中,typedef都使用的很多,在C代碼中尤其多,typedef與#define有些相似,其實是不同的,特別是在一些復(fù)雜的用法上,下面這篇文章主要給大家介紹了關(guān)于typedef和#define用法區(qū)別總結(jié)的相關(guān)資料,需要的朋友可以參考下2023-06-06