Brief discussion on the use of C + + log system Log4cxx _c language

Source: Internet
Author: User
Tags html form print format log4j
This article mainly from log4cxx level, layout, format, naming rules, filter several aspects introduced.

First, log4cxx naming rules
Logger is identified by the name of a string class, and the logger name is case-sensitive and has an inherited relationship between the names, with the parent name as the prefix, and the dot number. For example: X.y is X.y.z's father. A root logger (root logger) is the ancestor of all logger, which has the following attributes: 1 it always exists; 2 It cannot be obtained by name. Get root Logger by calling public static Logger Logger.getrootlogger (); by calling public static Logger Logger.getlogger (String name) or the public static Logger Logger.getlogger (Class clazz) Gets or creates a named Logger. The latter is equivalent to calling Logger.getlogger (Clazz.getname ()). In an object, call Logger.getlogger (class Clazz) with the class that the object belongs to to get the method that logger is considered to be the most sensible named logger that is currently known.

ii. log4cxx Log level description
Each logger is assigned a log level, which is used to control the output of the log information. A logger that is not assigned a level inherits the level of its nearest parent logger. Each output to the Logger log request (logging request) also has a level that is processed (called enabled) if the level of the request is greater than the level of the logger; Request will be ignored. It can be learned that: 1, the lower level of Logger, said the Logger more detailed 2, logging request levels higher, indicating that the logging request priority output 3, if there is no set logger (Logger), then it will Inherits the level of the nearest ancestor. Therefore, if you create a logger (Logger) in the package Com.foo.bar and there is no level set, it inherits the level of the Logger (Logger) created in the package Com.foo. If a logger (Logger) is not created in Com.foo, the log logger (Logger) created in Com.foo.bar inherits the level of the root logger (Logger). The root logger (Logger) is often instantiated and available, and its level is debug.
Five level definitions are predefined in the level class, and their size relationships are as follows: Level.all < Level.debug < Level.info < Level.warn < Level.error < Level.fatal < Level.off

Three, Log4cxx (log4j) Log Layout Introduction
Org.apache.log4j.HTMLLayout (layout in HTML form),
Org.apache.log4j.PatternLayout (You can specify layout patterns flexibly),
Org.apache.log4j.SimpleLayout (The level and information string that contains the log information),
Org.apache.log4j.TTCCLayout (contains information about the time, thread, category, and so on that the log was generated)

Four, log4cxx Log format information Introduction
LOG4J uses a print format similar to the printf function in c to format the log information, printing parameters as follows:
%M the message specified in the output code
%p output priority, i.e. Debug,info,warn,error,fatal
%r output the number of milliseconds it takes to boot to output the log information
The class to which the%c output belongs, usually the full name of the class in which it is located
%t output The name of the thread that generated the log event
%n output a carriage return line feed, Windows platform "RN", UNIX platform "n"
%d the date or time at which the log point is exported, the default format is ISO8601, or the format can be specified thereafter, such as:%d{yyyy MMM DD
HH:MM:SS,SSS}, output similar to: October 18, 2002 22:10:28,921%l output Log event occurrence location, including class name
, the thread that occurred, and the number of lines in the code.

Five, log4cxx Log Appender kind of introduction
Types of Appender provided by Log4cxx:
Org.apache.log4j.ConsoleAppender Console
Org.apache.log4j.DailyRollingFileAppender produces a log file every day
Org.apache.log4j.FileAppender file Org.apache.log4j.RollingFileAppender file size reached the specified size
Time to produce a new file

Six, log4cxx Log filter Introduction
Includes selection of filters and setting filter conditions, selectable filters include: Loglevelmatchfilter, Loglevelrangefilter, and Stringmatchfilter:
1. For loglevelmatchfilter, the filtration conditions include Logleveltomatch and Acceptonmatch (True|false), only if the loglevel value of log information is the same as that of Logleveltomatch, And Acceptonmatch is true to match.
2, for Loglevelrangefilter, filter conditions include loglevelmin, Loglevelmax and Acceptonmatch, only when log information loglevel in Loglevelmin, Matching occurs when the Loglevelmax is Acceptonmatch to true.
3, for Stringmatchfilter, filter conditions include Stringtomatch and Acceptonmatch, only when the loglevel value of log information and stringtomatch corresponding loglevel value and the same, and will match if Acceptonmatch is true.

Seven, log4cxx additivity attribute Introduction
It is the flag bit of the child logger whether to inherit the output source (Appender) of the parent logger. Specifically, the default situation logger will inherit the parent logger Appender, that is, the son logger will be in the logger of the Father Appender output. If Additivity is set to false, the child logger will only be exported in its own appender, not in the appender of the parent logger.

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.