---
title: "log4j 性能问题"
author: "zhouzhao21"
date: "2009-10-23T14:18:53Z"
tags: ["Apache", "log4j"]
slug: "log4j"
draft: false
lastmod: "2009-10-23T14:41:16Z"
id: 502596
url: "https://kyo-cc.iteye.com/blog/502596"
---

以前使用 log4j 时有条性能教条： 
在使用 log 之前，使用 isXXXEnabled() 函数来判断日志等级以提高程序性能。
不记得在哪看到讲现在的 log4j 版本不需要使用 isXXXEnabled() 函数来改进性能了。现在也找不到出处，看了下 log4j 代码（version 1.2.15），如下：
  public
  boolean isDebugEnabled() {
    if(repository.isDisabled( Level.DEBUG_INT))
      return false;
    return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel());
  }



  public
  void debug(Object message) {
    if(repository.isDisabled(Level.DEBUG_INT))
      return;
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) {
      forcedLog(FQCN, Level.DEBUG, message, null);
    }
  }

看来确实是不需要使用 isXXXEnabled() 函数来改进性能了。大家认为呢？