【log4cpp_学习】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<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fantongl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值