C ++ open-source cross-platform OJ system question determination core freejudger (iii) -- log4cxx uses multiple log files at the same time

Source: Internet
Author: User
Document directory
  • Prerequisites
  • Configure sub-logger
  • Complete configuration file used in the freejudger Project
  • Welcome to join

C ++ open-source cross-platform OJ system question determination core freejudger (iii) -- log4cxx uses multiple log files at the same time

By Ma Dongliang (cream Loki)

One man's war (http://blog.csdn.net/MDL13412)

Prerequisites

  • Log4cxxYou can use the configuration file to setLog4j compatibility;
  • Log4cxxLibrary to set the log stream, you only need to changeAppenderAttribute;
  • Log4cxxSupportedLogger Inheritance MechanismBy defaultInherit the parent LoggerOfAppender, Because you wantLog stream output to multiple filesTherefore, you needSet the inherited attribute of logger to false..
Configure sub-logger

To maximize flexibility,Log4cxxIntroducedSub-loggerThe concept of ownership andParent LoggerDifferent behavior, and in programming languagesOOPConsistent concept.

The following is a definitionSub-loggerCode, whereAp0YesLogger0UsedAppender:

log4j.logger.logger0 = TRACE, ap0

SetSub-loggerDo not inheritParent LoggerOfAppender:

log4j.additivity.logger0=false

SetSub-loggerFor the log file used, the following code willLogger0Set the log file0. Log:

log4j.appender.ap0.File=./0.log

Obtain the sub-logger instance in the program

First, load the configuration file:

Log4cxx: propertyconfigurator: Configure (configuration file name );

ObtainSub-loggerInstance:

Log4cxx: loggerptr logger = log4cxx: logger: getlogger (sub-logger name [for example, "logger0"] above);

Complete configuration file used in the freejudger Project

The following code configures eight Sub-logger, Used for the query thread log in the freejudger project:

log4j.additivity.gather = falselog4j.rootLogger=TRACElog4j.logger.logger0 = TRACE, ap0log4j.logger.logger1 = TRACE, ap1log4j.logger.logger2 = TRACE, ap2log4j.logger.logger3 = TRACE, ap3log4j.logger.logger4 = TRACE, ap4log4j.logger.logger5 = TRACE, ap5log4j.logger.logger6 = TRACE, ap6log4j.logger.logger7 = TRACE, ap7log4j.logger.logger8 = TRACE, ap8log4j.additivity.logger0=falselog4j.additivity.logger1=falselog4j.additivity.logger2=falselog4j.additivity.logger3=falselog4j.additivity.logger4=falselog4j.additivity.logger5=falselog4j.additivity.logger6=falselog4j.additivity.logger7=falselog4j.additivity.logger8=falselog4j.appender.logfile.encoding=UTF-8log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%nlog4j.appender.R.MaxFileSize=100KBlog4j.appender.ap0=org.apache.log4j.RollingFileAppenderlog4j.appender.ap0.ImmediateFlush=true log4j.appender.ap0.File=./0.loglog4j.appender.ap0.MaxBackupIndex=10log4j.appender.ap0.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap0.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%nlog4j.appender.ap1=org.apache.log4j.RollingFileAppenderlog4j.appender.ap1.ImmediateFlush=true log4j.appender.ap1.File=./1.loglog4j.appender.ap1.MaxBackupIndex=10log4j.appender.ap1.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap1.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%nlog4j.appender.ap2=org.apache.log4j.RollingFileAppenderlog4j.appender.ap2.ImmediateFlush=true log4j.appender.ap2.File=./2.loglog4j.appender.ap2.MaxBackupIndex=10log4j.appender.ap2.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap2.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%nlog4j.appender.ap3=org.apache.log4j.RollingFileAppenderlog4j.appender.ap3.ImmediateFlush=true log4j.appender.ap3.File=./3.loglog4j.appender.ap3.MaxBackupIndex=10log4j.appender.ap3.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap3.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%nlog4j.appender.ap4=org.apache.log4j.RollingFileAppenderlog4j.appender.ap4.ImmediateFlush=true log4j.appender.ap4.File=./4.loglog4j.appender.ap4.MaxBackupIndex=10log4j.appender.ap4.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap4.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%nlog4j.appender.ap5=org.apache.log4j.RollingFileAppenderlog4j.appender.ap5.ImmediateFlush=true log4j.appender.ap5.File=./5.loglog4j.appender.ap5.MaxBackupIndex=10log4j.appender.ap5.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap5.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%nlog4j.appender.ap6=org.apache.log4j.RollingFileAppenderlog4j.appender.ap6.ImmediateFlush=true log4j.appender.ap6.File=./6.loglog4j.appender.ap6.MaxBackupIndex=10log4j.appender.ap6.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap6.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%nlog4j.appender.ap7=org.apache.log4j.RollingFileAppenderlog4j.appender.ap7.ImmediateFlush=true log4j.appender.ap7.File=./7.loglog4j.appender.ap7.MaxBackupIndex=10log4j.appender.ap7.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap7.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%nlog4j.appender.ap8=org.apache.log4j.RollingFileAppenderlog4j.appender.ap8.ImmediateFlush=true log4j.appender.ap8.File=./8.loglog4j.appender.ap8.MaxBackupIndex=10log4j.appender.ap8.layout=org.apache.log4j.PatternLayoutlog4j.appender.ap8.layout.ConversionPattern=%5p %d{HH:mm:ss} -- %m%n
Welcome to join

Group 117975329, Verification informationCsdn.

Main maintainer:

  • Zhou Bao you_lan_hai@foxmail.com
  • Ma Dongliang mdl2009@vip.qq.com
Related Article

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.