zoukankan      html  css  js  c++  java
  • linux log4cplus安装和实例

    tar –xvf  log4cplus-1.1.3-rc5.tar.gz
    cd log4cplus-1.1.3-rc5
    configure --prefix=/usr/local/log4cplus
    make
    make install

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/log4cplus/lib/

    g++ -g  test_log4cplus.cpp -o process  -I/usr/local/log4cplus/include  -L/usr/local/log4cplus/lib -llog4cplus -lrt -lpthread

    #include <iostream>
    #include <log4cplus/logger.h>
    #include <log4cplus/loggingmacros.h>
    #include <log4cplus/configurator.h>
    #include <iomanip>
    #include <log4cplus/logger.h>
    #include <log4cplus/fileappender.h>
    #include <log4cplus/consoleappender.h>
    #include <log4cplus/layout.h>
    #include <time.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    using namespace std;
    using namespace log4cplus;
    int main()
    {
            /* step 1: Instantiate an appender object */
            SharedAppenderPtr  _append(new ConsoleAppender());
            _append->setName(LOG4CPLUS_TEXT("ConsoleAppender"));
            /* step 2: Instantiate a layout object */
            //std::string pattern = ;   
            std::auto_ptr<Layout> _layout(new PatternLayout(LOG4CPLUS_TEXT("%D{%m/%d/%y %H:%M:%S}  - %m [%l]%n")));
            /* step 3: Attach the layout object to the appender */
            _append->setLayout(_layout);
            /* step 4: Instantiate a logger object */
            Logger _logger = Logger::getInstance(LOG4CPLUS_TEXT("test"));
            /* step 5: Attach the appender object to the logger  */
            _logger.addAppender(_append);
            /* step 6: Set a priority for the logger  */
            _logger.setLogLevel(WARN_LOG_LEVEL);
            /* log activity */
            LOG4CPLUS_DEBUG(_logger, "This is the FIRST log message");
            LOG4CPLUS_WARN(_logger, "This is the SECOND log message");
            LOG4CPLUS_TRACE(_logger, "This is" << " just a t" << "est." << std::endl);
            LOG4CPLUS_DEBUG(_logger, "This is a bool: " << true);
            LOG4CPLUS_INFO(_logger, "This is a char: " << 'x');
            LOG4CPLUS_WARN(_logger, "This is a int: " << 1000);
            LOG4CPLUS_ERROR(_logger, "This is a long(hex): " << std::hex << 100000000);
            LOG4CPLUS_FATAL(_logger, "This is a double: " << std::setprecision(15) << 1.2345234234);
            return 0;
    }
  • 相关阅读:
    JAVA Unsafe类
    进程通信的五种普通方法
    监控API的实现 周末补
    INLINE HOOK 简单实现
    跨域资源请求方式
    在博客园放入“可运行”javascript代码
    一些学习资源
    XXE篇-本着就了解安全本质的想法,尽可能的用通俗易懂的语言去解释安全漏洞问题
    Mongodb注入
    SSRF篇-本着就了解安全本质的想法,尽可能的用通俗易懂的语言去解释安全漏洞问题
  • 原文地址:https://www.cnblogs.com/kaishan1990/p/7195823.html
Copyright © 2011-2022 走看看