Category 对log信息进行分类筛选,通俗的讲就是什么信息应该被输出,什么log信息应该被忽略
category 可以让log 按照classpath 分类
category 是有继承分层的,
命名为com.foo的category是被命名为com.foo.bar的category的parent,
最上层的Category被称为根(root category),根category有两个特点:
(1)它总是存在
(2)它的名字不能被直接得到
一个没有被定义优先级别的category将自动根据层次关系从它的parent或ancestor继承优先级别。
一个category 的log 信息默认将被输出到该category的appender 和 parent appender, 我们可以用additivity ="false" 限制。
<category name="com.foo.bar" additivity="false">
<priority value="info" />
<appender-ref ref="async" />
</category >
<priority value="info" />
<appender-ref ref="async" />
</category >
以 pgngn的 log4j.xml为例:
<!-- DVE base category -->
<category name="com.ericsson">
<priority value="WARN" />
</category>
<!-- API-PAS -->
<category name="com.ericsson.pas">
<priority value="WARN" />
</category>
<root>
<appender-ref ref="SERVERLOG" />
</root>
<root> 为root category, com.ericsson category 是 com.ericsson.pas 的parent.
org.quartz.core.JobRunShell 类的log 由于找不到对应的 category,最终由 root category 控制,并且root category 没有Level 限制,所以MCA21的quartz log会在pas-application.log中出现:
org.quartz.core.JobRunShell 类的log 由于找不到对应的 category,最终由 root category 控制,并且root category 没有Level 限制,所以MCA21的quartz log会在pas-application.log中出现:
2014-07-11 16:23:10,001 [eduler_Worker-5] DEBUG [org.quartz.core.JobRunShell] Calling execute on job DEFAULT.batchJobInvokerInvoker
===============补充160729
logger 已经替代caegory
下面是在log4j官方的API中写的,足以能解释logger与category的区别。。。
public class Category extends java.lang.Object implements Appender Attachable This class has been deprecated and replaced by the Logger subclass. It will be kept around to preserve backward compatibility until mid 2003.
Logger is a subclass of Category, i.e. it extends Category. In other words, a logger is a category. Thus, all operations that can be performed on a category can be performed on a logger. Internally, whenever log4j is asked to produce a Category object, it will instead produce a Logger object. Log4j 1.2 will never produce Category objects but only Logger instances. In order to preserve backward compatibility, methods that previously accepted category objects still continue to accept category objects.
For example, the following are all legal and will work as expected.
// Deprecated form:
Category cat = Category.getInstance("foo.bar")
// Preferred form for retrieving loggers:
Logger logger = Logger.getLogger("foo.bar")
The first form is deprecated and should be avoided.
There is absolutely no need for new client code to use or refer to the Category class. Whenever possible, please avoid referring to it or using it.
See the short manual for an introduction on this class.
See the document entitled preparing for log4j 1.3 for a more detailed discussion.
下面是在log4j官方的API中写的,足以能解释logger与category的区别。。。
public class Category extends java.lang.Object implements Appender Attachable This class has been deprecated and replaced by the Logger subclass. It will be kept around to preserve backward compatibility until mid 2003.
Logger is a subclass of Category, i.e. it extends Category. In other words, a logger is a category. Thus, all operations that can be performed on a category can be performed on a logger. Internally, whenever log4j is asked to produce a Category object, it will instead produce a Logger object. Log4j 1.2 will never produce Category objects but only Logger instances. In order to preserve backward compatibility, methods that previously accepted category objects still continue to accept category objects.
For example, the following are all legal and will work as expected.
// Deprecated form:
Category cat = Category.getInstance("foo.bar")
// Preferred form for retrieving loggers:
Logger logger = Logger.getLogger("foo.bar")
The first form is deprecated and should be avoided.
There is absolutely no need for new client code to use or refer to the Category class. Whenever possible, please avoid referring to it or using it.
See the short manual for an introduction on this class.
See the document entitled preparing for log4j 1.3 for a more detailed discussion.