Log4cxx C + + log library use with memory

Source: Internet
Author: User
Tags log4j

Log4cxx is a good library, using the configuration file can be very flexible to use it. To be specific, first of all, of course, in your C + + code, write a log of the various things

#include <log4cxx/logger.h>
#include <log4cxx/logstring.h>
#include <log4cxx/propertyconfigurator.h>

int _tmain(int argc, _TCHAR* argv[])
{
using namespace log4cxx;

// 读取配置文件
PropertyConfigurator::configure("log4cxx.cfg");

// 建立两个logger
LoggerPtr logger1 = Logger::getLogger("TraceYourMama");
LoggerPtr logger2 = Logger::getLogger("Patch");

LOG4CXX_TRACE(logger1, "跟踪");
LOG4CXX_WARN(logger1, "警告");
LOG4CXX_DEBUG(logger1, "调试");
LOG4CXX_ASSERT(logger1, false, "断言");
LOG4CXX_FATAL(logger1, "致命");

LOG4CXX_TRACE(logger2, "跟踪");
LOG4CXX_ERROR(logger2, "错误");
return 0;
}

In fact, in practical applications, each class can get a logger, and then in the configuration file to do the following settings:

# Set root logger to debug level
#log4j. ROOTLOGGER=TRACE,CA
Log4j.logger.traceyourmama=error,fa,ha
Log4j.logger.patch=trace,ca

#设置spirit为TRACE级别
#log4j. Spirit=debug
#log4j. Additivity.spirit=false


#%m-message
#%n-Return
#%d-time
#%.16c-logger name
#%-5p-log level
#%t-thread_id

#对Appender CA settings:
#这是一个控制台类型的Appender
#输出格式 (layout) to Patternlayout
Log4j.appender.ca= Org.apache.log4j.ConsoleAppender
Log4j.appender.ca.layout=org.apache.log4j.patternlayout
log4j.appender.ca.layout.conversionpattern=%d%-5p%.16c-%m%n


#对Appender fa set:
# This is a file type of Appender ,
# Its output file (file) is./debug.log,
# Output mode (Append) is overridden,
# output format (layout) is Patternlayout
Log4j.appender.fa= Org.apache.log4j.FileAppender
Log4j.appender.fa.file=./debug.log
Log4j.appender.fa.append=true
Log4j.appender.fa.layout=org.apache.log4j.patternlayout
#log4j. appender.fa.layout.conversionpattern=%d[%t]%-5p%.16c%x-%m%n
log4j.appender.fa.layout.conversionpattern=%d%-5p%.16c-%m%n

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.