您的位置:首页 > 其它

log4j中对于文件大小的限制

2013-07-11 17:00 211 查看
public
  static
  long toFileSize(String value, long dEfault) {
    if(value == null)
      return dEfault;

    String s = value.trim().toUpperCase();
    long multiplier = 1;
    int index;

    if((index = s.indexOf("KB")) != -1) {
      multiplier = 1024;
      s = s.substring(0, index);
    }
    else if((index = s.indexOf("MB")) != -1) {
      multiplier = 1024*1024;
      s = s.substring(0, index);
    }
    else if((index = s.indexOf("GB")) != -1) {
      multiplier = 1024*1024*1024;
      s = s.substring(0, index);
    }
    if(s != null) {
      try {
	return Long.valueOf(s).longValue() * multiplier;
      }
      catch (NumberFormatException e) {
	LogLog.error("[" + s + "] is not in proper int form.");
	LogLog.error("[" + value + "] not in expected format.", e);
      }
    }
    return dEfault;
  }


这一段时对于log4j中每一个备份文件的大小的计算,从代码上可以看书最后返回的是一个long类型的长整形。依据不同的单位,可设置的值也不同。

log4j中备份文件的最大数不能操作int的最大长度。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: