c++ 開源日誌庫選擇

來源:互聯網
上載者:User

liblogger

待選為 glog、log4cplus、log4cpp、log4cxx

目前準備使用glog,使用方便,效能也不錯,待進一步實驗,如果有不能滿足的功能就轉用 log4cplus,功能很全面,不過稍複雜些。

其它兩個都是三年前就沒更新,沒好感,暫不準備使用。

1.log4cplus

最新版本:1.1.0   2012-03-11

:http://sourceforge.net/projects/log4cplus/files/log4cplus-stable/1.1.0

功能全面,使用稍複雜。

程式碼範例: 

#include <log4cplus/layout.h>
#include <log4cplus/configurator.h>
#include <iomanip>
SharedAppenderPtr pFileAppender(new FileAppender("testlog.log"));
Logger pTestLogger = Logger::getInstance("LoggerName");
pTestLogger.addAppender(pFileAppender); 
sprintf(a,"%d",i);

LOG4CPLUS_WARN(pTestLogger, "This is a <Warn> log message..." << a );   

2.log4cxx

最新版本: 0.10.0  2008-04-03

:http://logging.apache.org/log4cxx/download.html

編譯很麻煩 新的版本0.10.0需要使用Apache的產品Ant來編譯,而Ant又需要JDK。。。

怕麻煩,沒有下載測試。 

 

3. glog

最新版本: 0.3.2  2012-1-12

:http://code.google.com/p/google-glog/downloads/list

使用方便,效能也不錯。

Google Glog 是一個C++語言的應用級日誌紀錄架構,提供了 C++ 風格的流操作和各種助手宏。

  Google glog是一個基於程式級記錄日誌資訊的c++庫,編程使用方式與c++的stream操作類似

程式碼範例:

#include <glog/logging.h>google::InitGoogleLogging(argv[0]);google::SetLogDestination(google::INFO,"./myInfo_");

LOG(INFO) << "This is a <Warn> log message..." << i; 

4. Log4cpp

 最新版1.0.x   2007-09-03

: http://sourceforge.net/projects/log4cpp/files

感覺 跟 log4cplus類似,結構稍簡單些,不過代碼也不少寫。 

 

#include <log4cpp/Category.hh>#include <log4cpp/PropertyConfigurator.hh>#include <log4cpp/NDC.hh>#include <log4cpp/FileAppender.hh>#include <log4cpp/BasicLayout.hh>log4cpp::Layout* layout = new log4cpp::BasicLayout();log4cpp::Appender* appender = new log4cpp::FileAppender("FileAppender", "./test_log4cpp1.log");appender->setLayout(layout);log4cpp::Category& warn_log = log4cpp::Category::getInstance("mywarn");warn_log.setAdditivity(false);warn_log.setAppender(appender);warn_log.setPriority(log4cpp::Priority::WARN);

warn_log.critStream() << "This is a <Warn> log message..." << i; 

  

5.  liblogger一款為C++開發的日誌工具,支援輸出到檔案、網路以及控制台 

參考地址:http://sourceforge.net/projects/liblogger/ 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.