0 Replies Latest reply on Nov 2, 2005 4:41 AM by wongtt78

    Undeployed application (EAR)  but log file is still opened.

    wongtt78

      Hi,

      How to close my log file when I undeploy my application?

      Reason for this, when I redeploy my application, my custom rolling appender failed to rename my previous log file. It is due to the file is still open.

      But when I shutdown JBoss, and then start it back, my rolling appender manage to rename the log file.

      Please refer to my custom rolling appender code below;

      public class Log4JRollingFileAppender extends RollingFileAppender {
       private String logDir = PropertiesUtil.getInstance().getString("log4j.log.dir", null);
       private String backupLogDir = PropertiesUtil.getInstance().getString("log4j.backup.log.dir", null);
       private boolean isAppend = PropertiesUtil.getInstance().getBoolean("log4j.is.append", true);
       private String logFileDateFormat = PropertiesUtil.getInstance().getString("log4j.file.date.format", null);
      
       public void rollOver(){
       Calendar calendar = Calendar.getInstance();
       SimpleDateFormat sdf = new SimpleDateFormat(logFileDateFormat);
      
       String logFilename = fileName.substring(fileName.lastIndexOf(File.separator), fileName.length());
      
       String backupLogFilename = backupLogDir + File.separator + logFilename + "." + sdf.format(calendar.getTime()) + ".log";
       File target = new File(backupLogFilename);
      
       closeFile();
       File file = new File(fileName);
      
       boolean result = file.renameTo(target);
       if (result){
       System.out.println("Successfully renaming file " + file + " to " + target);
       }else{
       System.out.println("Unable to renaming file " + file + " to " + target);
       }
      
       try{
       setFile(fileName, false, bufferedIO, bufferSize);
       }catch(IOException ioex){
       LogLog.error("setFile(" + fileName + ", false) call failed.", ioex);
       }
       }
      
       public void setFile(String filename){
       fileName = logDir + File.separator + filename;
      
       if(! isAppend){
       File file = new File(fileName);
       if (file.exists()){
       rollOver();
       }
       }
       }
      
       public String getFile(){
       return fileName;
       }
      }
      


      Please help me.

      Thank you.

      Sincerely
      David