- 浏览: 70849 次
- 性别:
- 来自: 深圳
最新评论
-
dudong0726:
不错
flex MP3播放器开发二(单歌曲播放) -
三尺寒冰:
楼主能共享一下源代码吗???
flex MP3播放器开发三(进度条显示) -
狂放不羁:
引用 另外 Hibernate 生成的 sql 也实在是太难看 ...
我为什么选择 iBatis 而不是 Hibernate(对于正在选型的人的建议) -
jimzhao:
有一个gif,按你的方法处理了一下,可以动画的时候,中间出现很 ...
imagick 处理 gif 切割 或者是 缩放 -
bigplum:
好东西
imagick 处理 gif 切割 或者是 缩放
Tomcat6下配置log4j
log4j配置到tomcat6可以看这里, tomcat6下配置log4j
引起log4j:ERROR Failed to rename的原因
引起log4j:ERROR Failed to rename的原因大致为
引用
因為他是採用renameTo檔名的方式,所以,有可能是因為有process咬住檔案(之前遇到的問題),或是對檔案讀寫的權限不足
关于使用renameTo需要注意的事项, 请看 请慎用java的File#renameTo(File)方法 , File.renameTo方法在linux下的问题
引起log4j:ERROR Failed to rename的条件
通常都是在配置文件采用Java代码
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender或者
Java代码
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1=org.apache.log4j.RollingFileAppender的情况下遇到"异常"提示.
和异常相关的log4j源代码
查看log4j的源代码,和log4j:ERROR Failed to rename异常相关的代码为
Java代码
/**
Rollover the current file to a new file.
*/
void rollOver() throws IOException {
/* Compute filename, but only if datePattern is specified */
if (datePattern == null) {
errorHandler.error("Missing DatePattern option in rollOver().");
return;
}
String datedFilename = fileName+sdf.format(now);
// It is too early to roll over because we are still within the
// bounds of the current interval. Rollover will occur once the
// next interval is reached.
if (scheduledFilename.equals(datedFilename)) {
return;
}
// close current file, and rename it to datedFilename
this.closeFile();
File target = new File(scheduledFilename);
if (target.exists()) {
target.delete();
}
File file = new File(fileName);
boolean result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
try {
// This will also close the file. This is OK since multiple
// close operations are safe.
this.setFile(fileName, false, this.bufferedIO, this.bufferSize);
}
catch(IOException e) {
errorHandler.error("setFile("+fileName+", false) call failed.");
}
scheduledFilename = datedFilename;
}
/**
* This method differentiates DailyRollingFileAppender from its
* super class.
*
* <p>Before actually logging, this method will check whether it is
* time to do a rollover. If it is, it will schedule the next
* rollover time and then rollover.
* */
protected void subAppend(LoggingEvent event) {
long n = System.currentTimeMillis();
if (n >= nextCheck) {
now.setTime(n);
nextCheck = rc.getNextCheckMillis(now);
try {
rollOver();
}
catch(IOException ioe) {
LogLog.error("rollOver() failed.", ioe);
}
}
super.subAppend(event);
}
}
/**
Rollover the current file to a new file.
*/
void rollOver() throws IOException {
/* Compute filename, but only if datePattern is specified */
if (datePattern == null) {
errorHandler.error("Missing DatePattern option in rollOver().");
return;
}
String datedFilename = fileName+sdf.format(now);
// It is too early to roll over because we are still within the
// bounds of the current interval. Rollover will occur once the
// next interval is reached.
if (scheduledFilename.equals(datedFilename)) {
return;
}
// close current file, and rename it to datedFilename
this.closeFile();
File target = new File(scheduledFilename);
if (target.exists()) {
target.delete();
}
File file = new File(fileName);
boolean result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
try {
// This will also close the file. This is OK since multiple
// close operations are safe.
this.setFile(fileName, false, this.bufferedIO, this.bufferSize);
}
catch(IOException e) {
errorHandler.error("setFile("+fileName+", false) call failed.");
}
scheduledFilename = datedFilename;
}
/**
* This method differentiates DailyRollingFileAppender from its
* super class.
*
* <p>Before actually logging, this method will check whether it is
* time to do a rollover. If it is, it will schedule the next
* rollover time and then rollover.
* */
protected void subAppend(LoggingEvent event) {
long n = System.currentTimeMillis();
if (n >= nextCheck) {
now.setTime(n);
nextCheck = rc.getNextCheckMillis(now);
try {
rollOver();
}
catch(IOException ioe) {
LogLog.error("rollOver() failed.", ioe);
}
}
super.subAppend(event);
}
}
重点在这里
Java代码
File file = new File(fileName);
boolean result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
File file = new File(fileName);
boolean result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
解决办法
解决办法为修改log4j的源代码, 修改
Java代码
boolean result = file.renameTo(target);
boolean result = file.renameTo(target);
为
Java代码
boolean result = copy(file, target);
boolean result = copy(file, target);
然后再添加copy()方法.
Java代码
/**
* Copies src file to dst file. If the dst file does not exist, it is
* created.8KB cache
*
* @param src
* @param dst
* @throws IOException
*/
boolean copy(File src, File dst) throws IOException {
try {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
return true;
} catch (FileNotFoundException e) {
LogLog.error("源文件不存在,或者目标文件无法被识别." );
return false;
} catch (IOException e) {
LogLog.error("文件读写错误.");
return false;
}
}
/**
* Copies src file to dst file. If the dst file does not exist, it is
* created.8KB cache
*
* @param src
* @param dst
* @throws IOException
*/
boolean copy(File src, File dst) throws IOException {
try {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
return true;
} catch (FileNotFoundException e) {
LogLog.error("源文件不存在,或者目标文件无法被识别." );
return false;
} catch (IOException e) {
LogLog.error("文件读写错误.");
return false;
}
}
此方法借鉴自 File Copy in Java 和 Java File Copy
后面的话
修改后的代码可以正常运行在tomcat6下, log文件替换正常. 没有高负载和集群环境下测试. 如有问题,还请大家积极反馈. 如果你有更好的办法请告诉我.
附件 : 包括修改后的org.apache.log4j.DailyRollingFileAppender类的源代码和已编译好的文件.
请用DailyRollingFileAppender.class替换log4j-1.2.15.jar包里相应的类.
log4j配置到tomcat6可以看这里, tomcat6下配置log4j
引起log4j:ERROR Failed to rename的原因
引起log4j:ERROR Failed to rename的原因大致为
引用
因為他是採用renameTo檔名的方式,所以,有可能是因為有process咬住檔案(之前遇到的問題),或是對檔案讀寫的權限不足
关于使用renameTo需要注意的事项, 请看 请慎用java的File#renameTo(File)方法 , File.renameTo方法在linux下的问题
引起log4j:ERROR Failed to rename的条件
通常都是在配置文件采用Java代码
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender或者
Java代码
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1=org.apache.log4j.RollingFileAppender的情况下遇到"异常"提示.
和异常相关的log4j源代码
查看log4j的源代码,和log4j:ERROR Failed to rename异常相关的代码为
Java代码
/**
Rollover the current file to a new file.
*/
void rollOver() throws IOException {
/* Compute filename, but only if datePattern is specified */
if (datePattern == null) {
errorHandler.error("Missing DatePattern option in rollOver().");
return;
}
String datedFilename = fileName+sdf.format(now);
// It is too early to roll over because we are still within the
// bounds of the current interval. Rollover will occur once the
// next interval is reached.
if (scheduledFilename.equals(datedFilename)) {
return;
}
// close current file, and rename it to datedFilename
this.closeFile();
File target = new File(scheduledFilename);
if (target.exists()) {
target.delete();
}
File file = new File(fileName);
boolean result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
try {
// This will also close the file. This is OK since multiple
// close operations are safe.
this.setFile(fileName, false, this.bufferedIO, this.bufferSize);
}
catch(IOException e) {
errorHandler.error("setFile("+fileName+", false) call failed.");
}
scheduledFilename = datedFilename;
}
/**
* This method differentiates DailyRollingFileAppender from its
* super class.
*
* <p>Before actually logging, this method will check whether it is
* time to do a rollover. If it is, it will schedule the next
* rollover time and then rollover.
* */
protected void subAppend(LoggingEvent event) {
long n = System.currentTimeMillis();
if (n >= nextCheck) {
now.setTime(n);
nextCheck = rc.getNextCheckMillis(now);
try {
rollOver();
}
catch(IOException ioe) {
LogLog.error("rollOver() failed.", ioe);
}
}
super.subAppend(event);
}
}
/**
Rollover the current file to a new file.
*/
void rollOver() throws IOException {
/* Compute filename, but only if datePattern is specified */
if (datePattern == null) {
errorHandler.error("Missing DatePattern option in rollOver().");
return;
}
String datedFilename = fileName+sdf.format(now);
// It is too early to roll over because we are still within the
// bounds of the current interval. Rollover will occur once the
// next interval is reached.
if (scheduledFilename.equals(datedFilename)) {
return;
}
// close current file, and rename it to datedFilename
this.closeFile();
File target = new File(scheduledFilename);
if (target.exists()) {
target.delete();
}
File file = new File(fileName);
boolean result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
try {
// This will also close the file. This is OK since multiple
// close operations are safe.
this.setFile(fileName, false, this.bufferedIO, this.bufferSize);
}
catch(IOException e) {
errorHandler.error("setFile("+fileName+", false) call failed.");
}
scheduledFilename = datedFilename;
}
/**
* This method differentiates DailyRollingFileAppender from its
* super class.
*
* <p>Before actually logging, this method will check whether it is
* time to do a rollover. If it is, it will schedule the next
* rollover time and then rollover.
* */
protected void subAppend(LoggingEvent event) {
long n = System.currentTimeMillis();
if (n >= nextCheck) {
now.setTime(n);
nextCheck = rc.getNextCheckMillis(now);
try {
rollOver();
}
catch(IOException ioe) {
LogLog.error("rollOver() failed.", ioe);
}
}
super.subAppend(event);
}
}
重点在这里
Java代码
File file = new File(fileName);
boolean result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
File file = new File(fileName);
boolean result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
解决办法
解决办法为修改log4j的源代码, 修改
Java代码
boolean result = file.renameTo(target);
boolean result = file.renameTo(target);
为
Java代码
boolean result = copy(file, target);
boolean result = copy(file, target);
然后再添加copy()方法.
Java代码
/**
* Copies src file to dst file. If the dst file does not exist, it is
* created.8KB cache
*
* @param src
* @param dst
* @throws IOException
*/
boolean copy(File src, File dst) throws IOException {
try {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
return true;
} catch (FileNotFoundException e) {
LogLog.error("源文件不存在,或者目标文件无法被识别." );
return false;
} catch (IOException e) {
LogLog.error("文件读写错误.");
return false;
}
}
/**
* Copies src file to dst file. If the dst file does not exist, it is
* created.8KB cache
*
* @param src
* @param dst
* @throws IOException
*/
boolean copy(File src, File dst) throws IOException {
try {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
return true;
} catch (FileNotFoundException e) {
LogLog.error("源文件不存在,或者目标文件无法被识别." );
return false;
} catch (IOException e) {
LogLog.error("文件读写错误.");
return false;
}
}
此方法借鉴自 File Copy in Java 和 Java File Copy
后面的话
修改后的代码可以正常运行在tomcat6下, log文件替换正常. 没有高负载和集群环境下测试. 如有问题,还请大家积极反馈. 如果你有更好的办法请告诉我.
附件 : 包括修改后的org.apache.log4j.DailyRollingFileAppender类的源代码和已编译好的文件.
请用DailyRollingFileAppender.class替换log4j-1.2.15.jar包里相应的类.
发表评论
-
我的淘宝群号
2011-05-31 12:40 2500人超级群,.淘宝互刷群,互刷信誉,群号码10461296 ... -
HttpClient 爬数据时 出现部分中文编码问题
2010-09-01 22:30 1308<html> <head> <m ... -
java 邮件群发
2010-08-13 22:38 1160摘 要:邮件群发是消息在Internet传递的最好办法,同时 ... -
关于struts2资源文件在页面动态取值问题
2010-04-20 20:16 972类似<s:text name="$ ... -
使用 XStream 把 Java 对象序列化为 XML
2009-05-21 15:04 974XML 序列化用处很多,包括对象持久化和数据传输。但是一些 X ... -
通过 Axis2 开发 Web 服务,第 1 部分: 通过 Axis2 运行时部署和使用简单 Web
2009-05-20 16:37 865本文介绍 Axis2 的新体系结构,并说明如何通过 Axis2 ... -
Axis2:会话(Session)管理
2009-05-20 16:07 1579WebService给人最直观的感 ... -
AXIS2中OMElement和Java对象之间的转换
2009-05-20 15:46 1460文章有错误,我要报错 ... -
axis2 开发
2009-05-19 22:03 10861,如果是单独开发,。axis2支持pring的装载,具体参见 ... -
PHP5中调用Java类
2009-05-13 10:28 973平台:Windows xp + apache2.0 + PHP ... -
使用dom4j的xpath解析xlm文件
2009-05-08 21:10 1178package com.njusc.xmlTest; ... -
Java和PHP一致的DES编码
2009-05-08 20:38 1678最近在做一个项目需要实现一个SSO,这个项目是由两个Team共 ... -
java 和 php共享memcached数据注意问题
2009-05-08 20:36 1120在很多时候,一台memcached server中的数据,需要 ... -
hibernate-memcached--在Hibernate中使用Memcached作为...
2009-05-08 20:33 1111今天在网上看到一个用Memcached作为Hibernate二 ... -
dom4j实战(一)——使用dom4j从XML中读取数据源配置
2009-05-08 20:30 962目前XML文件的应用越来越广泛,而操作XML的技术更有不少,其 ... -
Java操作XML文件 dom4j 篇
2009-05-08 11:30 833在项目中,我们很多都用到了xml文件,无论是参数配置还是与其它 ...
相关推荐
log4j:ERROR Failed to rename
log4j:ERROR Failed to rename错误; 网上查找了下原因,大概意思是日志文件始终被占有,所以当log4j对日志文件进行rename时,就发生了Failed to rename错误 。要修改log4j的源码,附件是我修改好后的,方便大家...
log4j:ERROR Failed to rename错误解决办法,修改源码里的DailyRollingFileAppender类,用此jar包就不会再出现ERROR Failed to rename的错误了
解决log4j:ERROR Failed to rename, win系统占用文件无法改名字的问题
log4j:ERROR Failed to rename错误解决办法 http://www.blogjava.net/DreamAngel/archive/2011/11/10/363400.html
针对log4j:ERROR Failed to rename的问题,修改源代码中的DailyRollingFileAppender.java文件,将rename改为copy。 该log4j-1.2.15.jar,就是修改后的jar包。 已经过测试,可以正常生成日志文件。
log4j:ERROR Failed to rename错误; 网上查找了下原因,大概意思是日志文件始终被占有,所以当log4j对日志文件进行rename时,就发生了Failed to rename错误 。要修改log4j的源码,附件是我修改好后的,方便大家...
在Windows操作系统中,文件的改名操作实际上涉及到了文件系统的元数据修改,这些操作可能需要系统级别的权限,因此在某些情况下,即使用户有文件的读写权限,也可能因为缺乏改名权限而失败。 总的来说,使用CFile::...
问题描述: 在使用git 进行提交时, 出现上面这个报错, 导致无法提交. 报错大致意思就是创建index.lock文件失败,因为已经存在index.lock文件了. index.lock文件是在.git下面, 而.git是一般是隐藏的, 那么可以通过以下...
以前我一直以为File#renameTo(File)方法与OS下面的 move/mv 命令是相同的,可以达到改名、移动文件的目的。不过后来经常发现问题:File#renameTo(File)方法会返回失败(false),文件没有移动,又查不出原因,再后来...
前言 最近发现了一个问题,运行 npm ... Error: EPERM: operation not permitted, rename ‘/usr/share/nginx/html/tanteng.me/node_modules/duplexify' -> ‘/usr/share/nginx/html/tanteng.me/node_modules/.duple
Error: EXDEV: cross-device link not permitted, rename ‘C:\Users\THEDIS~1\AppData\Local\Temp\upload_9b46f1afc2f9ade074037c3fb707d271’ -> ‘E:/node-rumen/tmp/test.png’ 文件上传的功能时候,调用fs....
### Python解决方案:WindowsError: [Error 2] 在使用Python进行文件操作时,经常会遇到一些错误,特别是当涉及到文件系统时。本篇文章将详细介绍如何处理一个常见的错误——`WindowsError: [Error 2]`,并提供一种...
今天小编就为大家分享一篇关于nodejs npm错误Error:UNKNOWN:unknown error,mkdir 'D:Developnodejsnode_global'at Error,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看...
总之,FTP4J为Android开发者提供了一种方便的FTP客户端解决方案,它可以帮助你在应用中实现高效、可靠的文件传输功能。正确集成并充分利用FTP4J的特性,将大大提高你的Android应用的实用性和竞争力。
在 ORACLE 中,重命名(Rename)一个表的命令是 ALTER TABLE old_name RENAME TO new_name,而不是 RENAME old_name TO new_name。 REname 命令只是 SQL*Plus 的命令,不能在其他程序中使用,如果将其放在 Java、...