Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果当天日志文件被删了,貌似就无法写文件了 #77

Closed
w2xx opened this issue Aug 2, 2019 · 4 comments
Closed

如果当天日志文件被删了,貌似就无法写文件了 #77

w2xx opened this issue Aug 2, 2019 · 4 comments

Comments

@w2xx
Copy link

w2xx commented Aug 2, 2019

貌似目前写文件时候没有判断文件是否存在,如果不存在也没有新建文件。只能杀进程重新初始化

@vip110880
Copy link

有解决吗?我这边上传日志到服务器,删除文件后发现没有创建新

@vip110880
Copy link

我这边自定义Printer,在doPrintln里做了下判断

private void doPrintln(long timeMillis, int logLevel, String tag, String msg) {
String lastFileName = this.writer.getLastFileName();
if (lastFileName == null || this.fileNameGenerator.isFileNameChangeable()) {
String newFileName = this.fileNameGenerator.generateFileName(logLevel, System.currentTimeMillis());
if (newFileName == null || newFileName.trim().length() == 0) {
throw new IllegalArgumentException("File name should not be empty.");
}

        if (!newFileName.equals(lastFileName)) {
            if (this.writer.isOpened()) {
                this.writer.close();
            }

            this.cleanLogFilesIfNecessary();
            if (!this.writer.open(newFileName)) {
                return;
            }

            lastFileName = newFileName;
        }
    }

    File lastFile = this.writer.getFile();

//这里做了判断处理
if (!lastFile.exists()) {
this.writer.open(lastFile.getName());
}

    if (this.backupStrategy.shouldBackup(lastFile)) {
        this.writer.close();
        File backupFile = new File(this.folderPath, lastFileName + ".bak");
        if (backupFile.exists()) {
            backupFile.delete();
        }

        lastFile.renameTo(backupFile);
        if (!this.writer.open(lastFileName)) {
            return;
        }
    }

    String flattenedLog = this.flattener.flatten(timeMillis, logLevel, tag, msg).toString();
    this.writer.appendLog(flattenedLog);
}

@w2xx
Copy link
Author

w2xx commented Sep 4, 2019

@vip110880 你是直接导入的源码吧。我没有导入源码,不知道有没有其他方式优化下

@elvishew
Copy link
Owner

Fixed in v1.8.0, close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants