zoukankan      html  css  js  c++  java
  • c++ 开源日志库选择

    待选为 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/ 

  • 相关阅读:
    如何搭建企业级中台系统
    Linux上安装git
    Jenkins的CI持续集成
    docker安装jenkins
    在线思维导图网站
    K8s容器编排
    MySQL存储引擎
    tomcat8 进入不了Manager App 界面 403 Access Denied
    IdeaVim-常用操作
    Node.js 安装及环境配置之 Windows 篇
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13318305.html
Copyright © 2011-2022 走看看