3_log4cpp的类介绍
1 log4cpp
log4cpp种最重要的概念有
Category
(种类)、Appender
(附加器)、layout
(布局)、Priority
(优先级)、NDC
(嵌套的诊断上下文)。
其中,Category、Appender与Layout三者的关系如下图所示:
2 Category类
log4cpp
有且只有一个根类rootCategory
,可以有多个子Category
组成树结构。
2.1 Name 属性
2.1.1 定义
/** The name of this category. */
const std::string _name;
2.1.2 getName方法
/**
* Return the category name.
* @returns The category name.
*/
virtual const std::string& getName() const throw();
2.2 Priority属性
日志优先级,
- 对于根
Category
,必须指定Priority
, - 对于非根
Category
,可以不指定Priority
,此时优先级继承自父Category
- 对于非根
Category
,当指定Priority
,此时优先级覆盖自父Category
2.2.1 定义
详细信息查阅Priority
类
/**
* The assigned priority of this category.
**/
volatile Priority::Value _priority;
2.2.2 setPriority方法
设置当前Category的优先级
/**
* Set the priority of this Category.
* @param priority The priority to set. Use Priority::NOTSET to let
* the category use its parents priority as effective priority.
* @exception std::invalid_argument if the caller tries to set
* Priority::NOTSET on the Root Category.
**/
virtual void setPriority(Priority::Value priority);
2.2.3 getPriority方法
获取当前对象的优先级
/**
* Returns the assigned Priority, if any, for this Category.
* @return Priority - the assigned Priority, can be Priority::NOTSET
**/
virtual Priority::Value getPriority() const throw();
2.2.4 setRootPriority方法
设置RootCategory
的优先级
/**
* Set the priority of the root Category.
* @param priority The new priority for the root Category
**/
static void setRootPriority(Priority::Value priority);
2.2.5 getRootPriority方法
获取root Category的优先级
/**
* Get the priority of the <code>root</code> Category.
* @returns the priority of the root category
**/
static Priority::Value getRootPriority() throw();
2.2.6 getChainedPriority方法
获取当前category继承表中的优先级,如果当前的优先值没有设置的话,则找他的父亲,如果父亲没有找到的话,他会继续向上找,因为root Category的优先值默认为Priority::INFO,所以肯定是能够找到的
/**
* Starting from this Category, search the category hierarchy for a
* set priority and return it. Otherwise, return the priority
* of the root category.
*
* <p>The Category class is designed so that this method executes as
* quickly as possible.
**/
virtual Priority::Value getChainedPriority() const throw();
2.2.7 isPriorityEnabled方法
返回当前拥有priority优先级
/**
* Returns true if the chained priority of the Category is equal to
* or higher than given priority.
* @param priority The priority to compare with.
* @returns whether logging is enable for this priority.
**/
virtual bool isPriorityEnabled(Priority::Value priority) const throw();
2.3 additivity属性
每一个Category
都有一个additivity
属性,该属性值默认为true
。
- 如果该值为
true
,则该Category<