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

日志文件被覆盖了 #125

Open
yjtacx opened this issue Feb 23, 2022 · 6 comments
Open

日志文件被覆盖了 #125

yjtacx opened this issue Feb 23, 2022 · 6 comments

Comments

@yjtacx
Copy link

yjtacx commented Feb 23, 2022

你好,我发现App启动时,偶尔会出现日志文件内容被覆盖掉了,而不是追加。我设置的是最多一个备份文件。这个什么原因呢?

@yjtacx
Copy link
Author

yjtacx commented Feb 23, 2022

@elvishew 这个问题确实比较怪,而且不是必现的,是否已经遇到过或者在更高版本处理了呢?

@elvishew
Copy link
Owner

你好,我发现App启动时,偶尔会出现日志文件内容被覆盖掉了,而不是追加。我设置的是最多一个备份文件。这个什么原因呢?

@yjtacx 请问是怎么设置的?暂时没听说过这个问题

@yjtacx
Copy link
Author

yjtacx commented May 5, 2022

下面是我的logger的创建方法,然后我新建了两个单例类,主要是为了写入两个不同的文件。
public static Logger getLogger(String logFileName, String tag, long debugMaxSize, long releaseMaxSize) {
Printer androidPrinter = new AndroidPrinter();
Printer filePrinter = new FilePrinter // Printer that print(save) the log to file
.Builder(getFileDir()) // Specify the directory path of log file(s)
.fileNameGenerator(new ChangelessFileNameGenerator(String.format("%s.log", logFileName))) // Default: ChangelessFileNameGenerator("log")
.backupStrategy(new FileSizeBackupStrategy2(BuildConfig.DEBUG ? debugMaxSize : releaseMaxSize, 1)) // Default: FileSizeBackupStrategy(1024 * 1024)
.flattener(new Flattener2() {

                @Override
                public CharSequence flatten(long timeMillis, int logLevel, String tag, String message) {
                    return timestampToString(timeMillis) + '|' + LogLevel.getShortLevelName(logLevel)

// + '|' + tag
+ '|' + message;
}
})
.build();
return XLog.tag(tag).printers(androidPrinter, filePrinter).build();
}

@yjtacx
Copy link
Author

yjtacx commented May 5, 2022

现象是这样的,比如我的两个日志文件:a.log和b.log内部的日志变成从同一时刻开始了的,之前的很多日志都丢了,而b.log的备份文件还在。

@elvishew
Copy link
Owner

elvishew commented May 5, 2022

@yjtacx 清理策略是怎样的,有没有可能在打开APP时,刚好清理策略生效,旧的日志被清了?

@yjtacx
Copy link
Author

yjtacx commented May 6, 2022

检查了下,没有自动清理任务,就是new FileSizeBackupStrategy2(BuildConfig.DEBUG ? debugMaxSize : releaseMaxSize, 1) 这个设置,这个我这也很难复现,只是有几个用户复现了,复现的情况基本都是bak.1文件存在,剩余的.log的文件被覆盖重写了。

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

2 participants