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

📄 timefileappender.java

📁 《JSP网站开发典型模块与实例精讲》一书光盘源码
💻 JAVA
字号:
package org.appfuse.util.log;

import java.io.*;

import org.apache.log4j.*;

public class TimeFileAppender
    extends DailyRollingFileAppender {
    public void setFile(String file) {
        String FILE_SEP = System.getProperty("file.separator");
        String val = file.trim();
        String tmpfileName = val.replace('/', FILE_SEP.charAt(0));
        if (!tmpfileName.startsWith(FILE_SEP)) {
            tmpfileName = FILE_SEP + tmpfileName;
        }
        String rootPath = "";
        java.io.File curFile = new java.io.File(".");
        try {
            rootPath = curFile.getCanonicalPath();
        }
        catch (IOException ex) {
            System.err.println("Get app root path error:" +
                               ex.getMessage());
        }
        fileName = rootPath + tmpfileName;
        //create non-exist path
        System.out.println("the root of log file: " + rootPath);
        System.out.println("the log file: " + fileName);

        int index = fileName.lastIndexOf(FILE_SEP);
        if (index > 0) {
            String sPath = fileName.substring(0, index);
            File path = new File(sPath);
            if (!path.exists()) {
                path.mkdirs();
            }
        }
    }
}

⌨️ 快捷键说明

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