Skip to content

Commit

Permalink
[Improvement] Add 20 MB limit for file logger, re-create the file if …
Browse files Browse the repository at this point in the history
…it more or less has reach 20MB
  • Loading branch information
rh-id committed Oct 22, 2021
1 parent bc2b468 commit 4e159dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions alogger/src/main/java/m/co/rh/id/alogger/FileLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ private synchronized void checkFileExist() throws IOException {
if (!mFile.exists()) {
mFile.getParentFile().mkdirs();
mFile.createNewFile();
} else {
// re-create file if log exceeds 20 MB
long size = mFile.length();
if (size > 20000000) {
mFile.delete();
mFile.createNewFile();
}
}
FileWriter fileWriter = new FileWriter(mFile, true);
BufferedWriter bw = new BufferedWriter(fileWriter);
Expand Down

0 comments on commit 4e159dc

Please sign in to comment.