⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 category.java

📁 apache的log4j源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    *  this case, regardless of whether the message is logged or not.    *    *  <p>If you are worried about speed, then you should write    *  <pre>    * 	 if(cat.isDebugEnabled()) {    * 	   cat.debug("This is entry number: " + i );    * 	 }    *  </pre>    *    *  <p>This way you will not incur the cost of parameter    *  construction if debugging is disabled for <code>cat</code>. On    *  the other hand, if the <code>cat</code> is debug enabled, you    *  will incur the cost of evaluating whether the category is debug    *  enabled twice. Once in <code>isDebugEnabled</code> and once in    *  the <code>debug</code>.  This is an insignificant overhead    *  since evaluating a category takes about 1%% of the time it    *  takes to actually log.    *    *  @return boolean - <code>true</code> if this category is debug    *  enabled, <code>false</code> otherwise.    *   */  public  boolean isDebugEnabled() {    if(repository.isDisabled( Level.DEBUG_INT))      return false;    return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel());  }  /**     Check whether this category is enabled for a given {@link     Level} passed as parameter.     See also {@link #isDebugEnabled}.     @return boolean True if this category is enabled for <code>level</code>.  */  public  boolean isEnabledFor(Priority level) {    if(repository.isDisabled(level.level))      return false;    return level.isGreaterOrEqual(this.getEffectiveLevel());  }  /**    Check whether this category is enabled for the info Level.    See also {@link #isDebugEnabled}.    @return boolean - <code>true</code> if this category is enabled    for level info, <code>false</code> otherwise.  */  public  boolean isInfoEnabled() {    if(repository.isDisabled(Level.INFO_INT))      return false;    return Level.INFO.isGreaterOrEqual(this.getEffectiveLevel());  }  /**     Log a localized message. The user supplied parameter     <code>key</code> is replaced by its localized version from the     resource bundle.     @see #setResourceBundle     @since 0.8.4 */  public  void l7dlog(Priority priority, String key, Throwable t) {    if(repository.isDisabled(priority.level)) {      return;    }    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {      String msg = getResourceBundleString(key);      // if message corresponding to 'key' could not be found in the      // resource bundle, then default to 'key'.      if(msg == null) {	msg = key;      }      forcedLog(FQCN, priority, msg, t);    }  }  /**     Log a localized and parameterized message. First, the user     supplied <code>key</code> is searched in the resource     bundle. Next, the resulting pattern is formatted using     {@link java.text.MessageFormat#format(String,Object[])} method with the     user supplied object array <code>params</code>.     @since 0.8.4  */  public  void l7dlog(Priority priority, String key,  Object[] params, Throwable t) {    if(repository.isDisabled(priority.level)) {      return;    }    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {      String pattern = getResourceBundleString(key);      String msg;      if(pattern == null)	msg = key;      else	msg = java.text.MessageFormat.format(pattern, params);      forcedLog(FQCN, priority, msg, t);    }  }  /**     This generic form is intended to be used by wrappers.   */  public  void log(Priority priority, Object message, Throwable t) {    if(repository.isDisabled(priority.level)) {      return;    }    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))      forcedLog(FQCN, priority, message, t);  } /**    This generic form is intended to be used by wrappers. */  public  void log(Priority priority, Object message) {    if(repository.isDisabled(priority.level)) {      return;    }    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))      forcedLog(FQCN, priority, message, null);  }  /**     This is the most generic printing method. It is intended to be     invoked by <b>wrapper</b> classes.     @param callerFQCN The wrapper class' fully qualified class name.     @param level The level of the logging request.     @param message The message of the logging request.     @param t The throwable of the logging request, may be null.  */  public  void log(String callerFQCN, Priority level, Object message, Throwable t) {    if(repository.isDisabled(level.level)) {      return;    }    if(level.isGreaterOrEqual(this.getEffectiveLevel())) {      forcedLog(callerFQCN, level, message, t);    }  }    /**      *  LoggerRepository forgot the fireRemoveAppenderEvent method,      *     if using the stock Hierarchy implementation, then call its fireRemove.      *     Custom repositories can implement HierarchyEventListener if they      *     want remove notifications.     * @param appender appender, may be null.     */   private void fireRemoveAppenderEvent(final Appender appender) {       if (appender != null) {         if (repository instanceof Hierarchy) {           ((Hierarchy) repository).fireRemoveAppenderEvent(this, appender);         } else if (repository instanceof HierarchyEventListener) {             ((HierarchyEventListener) repository).removeAppenderEvent(this, appender);         }       }   }  /**     Remove all previously added appenders from this Category     instance.     <p>This is useful when re-reading configuration information.  */  synchronized  public  void removeAllAppenders() {    if(aai != null) {      Vector appenders = new Vector();      for (Enumeration iter = aai.getAllAppenders(); iter.hasMoreElements();) {          appenders.add(iter.nextElement());      }      aai.removeAllAppenders();      for(Enumeration iter = appenders.elements(); iter.hasMoreElements();) {          fireRemoveAppenderEvent((Appender) iter.nextElement());      }      aai = null;    }  }  /**     Remove the appender passed as parameter form the list of appenders.     @since 0.8.2  */  synchronized  public  void removeAppender(Appender appender) {    if(appender == null || aai == null)      return;    boolean wasAttached = aai.isAttached(appender);    aai.removeAppender(appender);    if (wasAttached) {        fireRemoveAppenderEvent(appender);    }  }  /**     Remove the appender with the name passed as parameter form the     list of appenders.     @since 0.8.2 */  synchronized  public  void removeAppender(String name) {    if(name == null || aai == null) return;    Appender appender = aai.getAppender(name);    aai.removeAppender(name);    if (appender != null) {        fireRemoveAppenderEvent(appender);    }  }  /**     Set the additivity flag for this Category instance.     @since 0.8.1   */  public  void setAdditivity(boolean additive) {    this.additive = additive;  }  /**     Only the Hiearchy class can set the hiearchy of a     category. Default package access is MANDATORY here.  */  final  void setHierarchy(LoggerRepository repository) {    this.repository = repository;  }  /**     Set the level of this Category. If you are passing any of     <code>Level.DEBUG</code>, <code>Level.INFO</code>,     <code>Level.WARN</code>, <code>Level.ERROR</code>,     <code>Level.FATAL</code> as a parameter, you need to case them as     Level.     <p>As in <pre> &nbsp;&nbsp;&nbsp;logger.setLevel((Level) Level.DEBUG); </pre>     <p>Null values are admitted.  */  public  void setLevel(Level level) {    this.level = level;  }  /**     Set the level of this Category.     <p>Null values are admitted.     @deprecated Please use {@link #setLevel} instead.  */  public  void setPriority(Priority priority) {    this.level = (Level) priority;  }  /**     Set the resource bundle to be used with localized logging     methods {@link #l7dlog(Priority,String,Throwable)} and {@link     #l7dlog(Priority,String,Object[],Throwable)}.     @since 0.8.4   */  public  void setResourceBundle(ResourceBundle bundle) {    resourceBundle = bundle;  }  /**     Calling this method will <em>safely</em> close and remove all     appenders in all the categories including root contained in the     default hierachy.     <p>Some appenders such as {@link org.apache.log4j.net.SocketAppender}     and {@link AsyncAppender} need to be closed before the     application exists. Otherwise, pending logging events might be     lost.     <p>The <code>shutdown</code> method is careful to close nested     appenders before closing regular appenders. This is allows     configurations where a regular appender is attached to a category     and again to a nested appender.     @deprecated Please use {@link LogManager#shutdown()} instead.     @since 1.0  */  public  static  void shutdown() {    LogManager.shutdown();  }  /**    Log a message object with the {@link Level#WARN WARN} Level.    <p>This method first checks if this category is <code>WARN</code>    enabled by comparing the level of this category with {@link    Level#WARN WARN} Level. If the category is <code>WARN</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    proceeds to call all the registered appenders in this category and    also higher in the hieararchy depending on the value of the    additivity flag.    <p><b>WARNING</b> Note that passing a {@link Throwable} to this    method will print the name of the Throwable but no stack trace. To    print a stack trace use the {@link #warn(Object, Throwable)} form    instead.  <p>    @param message the message object to log.  */  public  void warn(Object message) {    if(repository.isDisabled( Level.WARN_INT))      return;    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))      forcedLog(FQCN, Level.WARN, message, null);  }  /**   Log a message with the <code>WARN</code> level including the   stack trace of the {@link Throwable} <code>t</code> passed as   parameter.   <p>See {@link #warn(Object)} for more detailed information.   @param message the message object to log.   @param t the exception to log, including its stack trace.  */  public  void warn(Object message, Throwable t) {    if(repository.isDisabled(Level.WARN_INT))      return;    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))      forcedLog(FQCN, Level.WARN, message, t);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -