强大的log4cxx,rapidxml,boost组合起来更加强大:
#include "stdafx.h"
// include log4cxx header files.
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/exception.h>
#include <rapidxml.hpp>
#include <rapidxml_print.hpp>
#include <iostream>
#include <boost/format.hpp>
log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
log4cxx::LoggerPtr logger2(log4cxx::Logger::getLogger("secondlog"));
log4cxx::LoggerPtr logger3(log4cxx::Logger::getLogger("thirdlog"));
std::string rapidxml2string(const rapidxml::xml_document<>& doc)
{
std::string doc_s;
rapidxml::print(std::back_inserter(doc_s), doc, 0);
return doc_s;
}
int main(int argc, char **argv)
{
int result = EXIT_SUCCESS;
try
{
LOG4CXX_INFO(logger, "Entering application.");
for ( int i=0; i<10; i++ )
{
LOG4CXX_INFO(logger, "loop index:" << i);
}
for ( int j=0; j<1000; j++ )
{
LOG4CXX_INFO(logger2, "second loop index:" << j);
}
for ( int j=0; j<1000; j++ )
{
LOG4CXX_INFO(logger3, "third loop index:" << j);
}
std::string xml = "<r><name>ken</name><birth nation=\"china\">1983-11</birth></r>";
rapidxml::xml_document<> doc; // character type defaults to char
doc.parse<0>((char*)xml.c_str()); // 0 means default parse flags
std::cout << "Name of my first node is: " << doc.first_node()->name() << "\n";
/// rapid xml control routine
// access
rapidxml::xml_node<> *node = doc.first_node()->first_node("birth");
std::cout << "Node birth has value " << node->value() << "\n";
for (rapidxml::xml_attribute<> *attr = node->first_attribute();
attr; attr = attr->next_attribute())
{
std::cout << "Node birth has attribute " << attr->name() << " ";
std::cout << "with value " << attr->value() << "\n";
}
// modify
rapidxml::xml_node<>* new_node = doc.allocate_node(rapidxml::node_element, "a", "Google");
doc.first_node()->append_node(new_node);
rapidxml::xml_attribute<> *attr = doc.allocate_attribute("href", "google.com");
new_node->append_attribute(attr);
// print
std::cout << "after modified:" << std::endl;
std::string doc_s = rapidxml2string(doc);
LOG4CXX_INFO(logger, boost::format("final xml:%s") % doc_s); // boost::format+log4cxx,powerful
LOG4CXX_INFO(logger, "Exiting application.");
}
catch(log4cxx::helpers::Exception& e)
{
result = EXIT_FAILURE;
}
getchar();
return result;
}
log4cxx的典型配置文件:
log4j.rootLogger=DEBUG, stdout, R
#log4j.rootLogger=debug, R
#log4j.rootLogger=debug, stdout
#log4j.rootLogger=debug
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log/example.log
log4j.appender.R.MaxFileSize=2KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %p %t %c - %m%n
#second log
log4j.logger.secondlog=DEBUG, a2
log4j.additivity.secondlog = false
log4j.appender.a2=org.apache.log4j.RollingFileAppender
log4j.appender.a2.File=log/second2.log
log4j.appender.a2.MaxFileSize=2KB
# Keep 5 backup file
log4j.appender.a2.MaxBackupIndex=5
log4j.appender.a2.layout=org.apache.log4j.PatternLayout
log4j.appender.a2.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %p %t %c - %m%n
#third log
log4j.logger.thirdlog=DEBUG, a3
log4j.additivity.thirdlog = false
log4j.appender.a3=org.apache.log4j.RollingFileAppender
log4j.appender.a3.File=log/thirdlog.log
log4j.appender.a3.MaxFileSize=2KB
# Keep 5 backup file
log4j.appender.a3.MaxBackupIndex=5
log4j.appender.a3.layout=org.apache.log4j.PatternLayout
log4j.appender.a3.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %p %t %c - %m%n
分享到:
相关推荐
自己用c++,vs2005写的一个log4cxx的日志程序,可以进行日志记录,对哪些还不熟悉怎么使用log4cxx的人来说应该有点用
本文阐述了如何在Windows下以及linux下使用高性能的日志系统log4cxx。注意,在嵌入式linux的环境下使用的过程中发现有内存泄漏问题。关于该问题的解决参考本人上传的另外一份有关 log4cxx 的文档。
在win10下面用vs2019编译的最新的apache-log4cxx-0.13.0库,里面vs工程都有,在build_win目录下面。
Log4cxx在C++领域的运用,包含链接库、测试demo以及相关配置说明,经VS2015实测OK
库是在window平台下编译,64位,...还写了一个使用log4cxx库文件的示例程序,使用Qt编写,亲测可用,示例程序内含配置文件示例。 如果您是Qt程序源,使用该库时可直接在pro文件中加入log4cxx.pri文件即可完成库的加载。
log4cxx编译所需压缩包,和用vs2019编译好的库
Log4cxx是开放源代码项目Apache LoggingService的子项目之一,是Java社区著名的log4j的c++移植版,用于为C++程序提供日志功能,以便开发者对目标程序进行调试和审计。 这里已做好编译的dll,lib库文件,可以直接...
log4cxx是apache的一款优秀的日志文件记录工具,然而,下载能够编译成功的,即log4cxx + apr + apr-util 能够兼容,编译通过的。当时就因为下载的不能够兼容,费了好的的功夫,现在把他们上传上来,供后来人使用
Log4cxx 使用编译,在2010 出现的错误解决方案。
log4cxx是apache开源基金组织下一个很强的日志操作项目,和java平台下的log4j功能一样强大,深受广大c++程序员喜爱; 苦于众所周知的原因,apahce没有提供log4cxx-0.10.0基于visual studio的项目文件; 本资源包含了...
log4cxx全套源代码apache-log4cxx+apr+apr-util及需要的工具sed
将log4cxx封装成LOG(level,format,content)的形式,方便使用,也可用于其他开源日志框架的封装,包含log4cxx的详细配置文件。
C和C++的经典日志模块log4cxx和其开发示例源码,是apache log4j的C、C++移植类,性能强大,也是公司使用的首选。
已经编译好的动态库,log4cxx.dll和log4cxx.dll.lib都有,还有代码等。
apache-log4cxx-0.10.0.zip 中包含 include和lib两个目录,lib下的 log4cxx.dll 是用apache-log4cxx-0.10.0开源库编译出来的一个动态库。在其他工程中直接饮用该dll,就可以部署一个简单的日志解决方案
log4cxx ,日志类,源代码 log4cxx是Java社区著名的log4j的c++移植版,用于为C++程序提供日志功能,以便开发者对目标程序进行调试和审计,log4cxx是apache软件基金会的开源项目,基于APR实现跨平台支持。一个良好的...
花了3天时间,终于在Visual Studio 2015下编译通过了,附件包含apache-log4cxx-0.10.0、apr和apr-util共3个文件夹,请直接用VS2015打开apache-log4cxx-0.10.0\projects\log4cxx.sln,然后选Release,编译log4cxx即可
Log4cxx是Apache开源日志项目中的C++版本,Apache的开源日志项目移植于Java社区著名的Log4j,后来经过代码移植,现已有.NET、C++和PHP版本的日志库了。在很多的应用程序中,日志的使用非常的普遍
log4cxx是Apache旗下的日志工具,本资源中有编译 log4cxx所要用的所有的源码,且有编译帮助文档,以及一个测试工程。 本人亲测:100万条,用了8秒;1000万条日志,用了83秒,文件大小为810M 配置:在虚拟机里面测的...