为不用和其他级别冲突,有时候需要自己定义级别,查看源码,代码如下:

package org.apache.log4j;/**<font color="#AA4444">Refrain from using this class directly, usethe {@link Level} class instead</font>.@author Ceki Gülcü */
public class Priority {transient int level;transient String levelStr;transient int syslogEquivalent;public final static int OFF_INT = Integer.MAX_VALUE;public final static int FATAL_INT = 50000;public final static int ERROR_INT = 40000;public final static int WARN_INT  = 30000;public final static int INFO_INT  = 20000;public final static int DEBUG_INT = 10000;//public final static int FINE_INT = DEBUG_INT;public final static int ALL_INT = Integer.MIN_VALUE;

通过代码可以出来Level替代了Priority,

那么Level代码如下:

/**Defines the minimum set of levels recognized by the system, that is<code>OFF</code>, <code>FATAL</code>, <code>ERROR</code>,<code>WARN</code>, <code>INFO</code, <code>DEBUG</code> and<code>ALL</code>.<p>The <code>Level</code> class may be subclassed to define a largerlevel set.@author Ceki Gülcü*/
public class Level extends Priority implements Serializable {/*** TRACE level integer value.* @since 1.2.12*/public static final int TRACE_INT = 5000;/**The <code>OFF</code> has the highest possible rank and isintended to turn off logging.  */final static public Level OFF = new Level(OFF_INT, "OFF", 0);/**The <code>FATAL</code> level designates very severe errorevents that will presumably lead the application to abort.*/final static public Level FATAL = new Level(FATAL_INT, "FATAL", 0);/**The <code>ERROR</code> level designates error events thatmight still allow the application to continue running.  */final static public Level ERROR = new Level(ERROR_INT, "ERROR", 3);/**The <code>WARN</code> level designates potentially harmful situations.*/final static public Level WARN  = new Level(WARN_INT, "WARN",  4);/**The <code>INFO</code> level designates informational messagesthat highlight the progress of the application at coarse-grainedlevel.  */final static public Level INFO  = new Level(INFO_INT, "INFO",  6);/**The <code>DEBUG</code> Level designates fine-grainedinformational events that are most useful to debug anapplication.  */final static public Level DEBUG = new Level(DEBUG_INT, "DEBUG", 7);

Category如下:

/*** <font color="#AA2222"><b>This class has been deprecated and* replaced by the {@link Logger} <em>subclass</em></b></font>. It* will be kept around to preserve backward compatibility until mid* 2003.* * <p><code>Logger</code> is a subclass of Category, i.e. it extends* Category. In other words, a logger <em>is</em> 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 <em>never</em> produce Category objects but* only <code>Logger</code> instances. In order to preserve backward* compatibility, methods that previously accepted category objects* still continue to accept category objects.* * <p>For example, the following are all legal and will work as* expected.* <pre>// Deprecated form:Category cat = Category.getInstance("foo.bar")// Preferred form for retrieving loggers:Logger logger = Logger.getLogger("foo.bar")</pre>*  <p>The first form is deprecated and should be avoided.* *  <p><b>There is absolutely no need for new client code to use or*  refer to the <code>Category</code> class.</b> Whenever possible,*  please avoid referring to it or using it.* * <p>See the <a href="../../../../manual.html">short manual</a> for an* introduction on this class.* <p>* See the document entitled <a href="http://www.qos.ch/logging/preparingFor13.html">preparing*  for log4j 1.3</a> for a more detailed discussion.** @author Ceki Gülcü* @author Anders Kristensen */
public class Category implements AppenderAttachable {/**The hierarchy where categories are attached to by default.*///static//public//final Hierarchy defaultHierarchy = new Hierarchy(new//                      RootCategory(Level.DEBUG));/**The name of this category.*/protected String   name;/**The assigned level of this category.  The<code>level</code> variable need not be assigned a value inwhich case it is inherited form the hierarchy.  */volatile protected Level level;/**The parent of this category. All categories have at least oneancestor which is the root category. */volatile protected Category parent;/**The fully qualified name of the Category class. See also thegetFQCN method. */private static final String FQCN = Category.class.getName();protected ResourceBundle resourceBundle;// Categories need to know what Hierarchy they are inprotected LoggerRepository repository;AppenderAttachableImpl aai;/** Additivity is set to true by default, that is children inheritthe appenders of their ancestors by default. If this variable isset to <code>false</code> then the appenders found in theancestors of this category are not used. However, the childrenof this category will inherit its appenders, unless the childrenhave their additivity flag set to <code>false</code> too. Seethe user manual for more details. */protected boolean additive = true;/**This constructor created a new <code>Category</code> instance andsets its name.<p>It is intended to be used by sub-classes only. You should notcreate categories directly.@param name The name of the category.*/protectedCategory(String name) {this.name = name;}/**Add <code>newAppender</code> to the list of appenders of thisCategory instance.<p>If <code>newAppender</code> is already in the list ofappenders, then it won't be added again.*/synchronizedpublicvoid addAppender(Appender newAppender) {if(aai == null) {aai = new AppenderAttachableImpl();}aai.addAppender(newAppender);repository.fireAddAppenderEvent(this, newAppender);}/**If <code>assertion</code> parameter is <code>false</code>, thenlogs <code>msg</code> as an {@link #error(Object) error} statement.<p>The <code>assert</code> method has been renamed to<code>assertLog</code> because <code>assert</code> is a languagereserved word in JDK 1.4.@param assertion@param msg The message to print if <code>assertion</code> isfalse.@since 1.2 */publicvoid assertLog(boolean assertion, String msg) {if(!assertion)this.error(msg);}/**Call the appenders in the hierrachy starting at<code>this</code>.  If no appenders could be found, emit awarning.<p>This method calls all the appenders inherited from thehierarchy circumventing any evaluation of whether to log or notto log the particular log request.@param event the event to log.  */publicvoid callAppenders(LoggingEvent event) {int writes = 0;for(Category c = this; c != null; c=c.parent) {// Protected against simultaneous call to addAppender, removeAppender,...synchronized(c) {if(c.aai != null) {writes += c.aai.appendLoopOnAppenders(event);}if(!c.additive) {break;}}}if(writes == 0) {repository.emitNoAppenderWarning(this);}}/**Close all attached appenders implementing the AppenderAttachableinterface.@since 1.0*/synchronizedvoid closeNestedAppenders() {Enumeration enumeration = this.getAllAppenders();if(enumeration != null) {while(enumeration.hasMoreElements()) {Appender a = (Appender) enumeration.nextElement();if(a instanceof AppenderAttachable) {a.close();}}}}/**Log a message object with the {@link Level#DEBUG DEBUG} level.<p>This method first checks if this category is <code>DEBUG</code>enabled by comparing the level of this category with the {@linkLevel#DEBUG DEBUG} level. If this category is<code>DEBUG</code> enabled, then it converts the message object(passed as parameter) to a string by invoking the appropriate{@link org.apache.log4j.or.ObjectRenderer}. It then proceeds to call all theregistered appenders in this category and also higher in thehierarchy depending on the value of the additivity flag.<p><b>WARNING</b> Note that passing a {@link Throwable} to thismethod will print the name of the <code>Throwable</code> but nostack trace. To print a stack trace use the {@link #debug(Object,Throwable)} form instead.@param message the message object to log. */publicvoid debug(Object message) {if(repository.isDisabled(Level.DEBUG_INT))return;if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) {forcedLog(FQCN, Level.DEBUG, message, null);}}/**Log a message object with the <code>DEBUG</code> level includingthe stack trace of the {@link Throwable} <code>t</code> passed asparameter.<p>See {@link #debug(Object)} form for more detailed information.@param message the message object to log.@param t the exception to log, including its stack trace.  */publicvoid debug(Object message, Throwable t) {if(repository.isDisabled(Level.DEBUG_INT))return;if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel()))forcedLog(FQCN, Level.DEBUG, message, t);}/**Log a message object with the {@link Level#ERROR ERROR} Level.<p>This method first checks if this category is <code>ERROR</code>enabled by comparing the level of this category with {@linkLevel#ERROR ERROR} Level. If this category is <code>ERROR</code>enabled, then it converts the message object passed as parameter

已经被Logger类替代了,修改新的级别,就找到Error类似的级别 拷贝修改即可。

log4j自定义新的级别相关推荐

  1. Tomcat下项目调整Log4J的console输出级别,减少输出信息

    场景 输出优先级,由低到高 DEBUG,INFO,WARN,ERROR,FATAL 输出方式说明 org.apache.log4j.ConsoleAppender(控制台),   org.apache ...

  2. 【Java编程系列】log4j配置日志按级别分别生成日志文件

    热门系列: [Java编程系列]WebService的使用 [Java编程系列]在Spring MVC中使用工具类调用Service层时,Service类为null如何解决 [Java编程系列]Spr ...

  3. Log4j自定义Appender介绍

    最初想要在执行一段业务逻辑的时候调用一个外部接口记录审计信息,一直找不到一个比较优雅的方式,经过讨论觉得log4j自定义的appender或许可以实现此功能.后来就了解了一下log4j的这部分. Ap ...

  4. sap新总账中 CodingBlock客户化自定义新字段方法

    CodingBlock客户化自定义新字段   1.Coding Block新字段 财务会计(新)-财务会计基本设置(新)-分类帐-字段-客户字段-编辑编码块(OXK3): 添加字段如图:   该步骤比 ...

  5. Spring Boot log4j多环境日志级别的控制

    之前介绍了在<Spring boot中使用log4j>,仅通过log4j.properties对日志级别进行控制,对于需要多环境部署的环境不是很方便,可能我们在开发环境大部分模块需要采用D ...

  6. **如何在catia工程图中自定义新的制图标准**

    如何在catia工程图中自定义新的制图标准 Catia中已有的制图标准:JIS.ISO.ANSI,没有国标GB,可通过加入GB.xml文件方式来获得配置文件,对于企业标准,需要以自定义的方式进行,以下 ...

  7. log4j对象改变日志级别

    log4j对象改变日志级别可批量的改变所有级别,或是根据条件改变日志级别. log4j配置文件: log4j.rootLogger=ERROR,FILE,CONSOLE,EXECPTION #log4 ...

  8. Redis数据实战之GEO在LBS中应用与自定义新数据类型

    Redis数据实战之GEO在LBS中应用与自定义新数据类型 引言 面向 LBS 应用的 GEO 数据类型 GEO 的底层结构 GeoHash 的编码方法 如何操作 GEO 类型 如何自定义数据类型 R ...

  9. slf4j-log4j12加log4j自定义配置包路径日志输出

    项目日志在定位问题原因上起着重要的作用,有用的日志输出能提高解决问题的效率,所以日志配置还是很关键的,对一个项目来说有用的日志包路径一般都是项目自己包路径下的日志,集成的框架和依赖包中的包路径下的日志 ...

最新文章

  1. FPGA之道(32)Verilog基本程序框架
  2. 每个程序员都必须知道的8种数据结构
  3. python装饰器实例-Python装饰器原理与简单用法实例分析
  4. H. Texas hold'em Poker(2019ICPC区域网络赛沈阳站)
  5. coo_maxtrix保存到本地
  6. java去除json 转移,Spring MVC返回的json去除根节点名称的方法
  7. linux 解压安卓内核,解压内核镜像
  8. mamp安装php扩展,向MAMP添加GMP PHP扩展
  9. LeetCode(617)——合并二叉树(JavaScript)
  10. 关于sql server 的那些事
  11. 【转】常用 blas 函数
  12. QT-OpcUa使用open62541相关释疑
  13. java如何进行传感器数据传输_使用Wio Terminal通过HTTP请求获取并展示传感器实时数据...
  14. 王校长一分钟能吃多少热狗?| 小游戏 1
  15. 2021年高压电工考试及高压电工模拟试题
  16. P4556-线段树合并,差分
  17. Matlab学习——求解微分方程(组)
  18. 2021金昌市一中高考成绩查询,2021届甘肃省金昌市一中高三下学期高考一模考试数学(理)试卷参考答案.docx...
  19. python houdini_Houdini Python基础一安装
  20. java ppt 转pdf_Java 将PPT转为PNG/PDF/SVG/PPTX

热门文章

  1. uniapp拍照上传功能
  2. 扫雷——关于展开空格的算法
  3. 我的世界服务器怎么弄无限矿物,《我的世界》无限存储空间设备如何制作?
  4. 被遗忘的数学家!曾提出最接地气的数学定理,可以计算男朋友真不真心的那种......
  5. 新IT引领新经济 新华三惠州云博会展现“云”魅力
  6. 计算机屏幕自己动,ipad屏幕失灵自己乱跳怎么办【图文】
  7. 新兴职业背后的认知逻辑
  8. 寒假每日一题题解(1.29)摘花生(DP水题)
  9. 副业项目:今日头条音频项目,日入200+
  10. C#入门4——税收计算