-
Notifications
You must be signed in to change notification settings - Fork 304
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
PAYARA-2822 Access logs are not being purged #2824
Conversation
* If undefined or value is less than 0, all history log are preserved. | ||
*/ | ||
private void cleanUpHistoryLogFiles() { | ||
if (maxHistoryFiles == 0 || maxHistoryFiles < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be written as <=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svendiedrichsen thanks for the review.
|
||
File[] allFilesInDirectory = fileDirectory.listFiles(); | ||
ArrayList<String> candidateListOfLogFiles = new ArrayList<>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use List<File>
? You could spare some File-Instance creation later on.
&& allFilesInDirectory[i].isFile() | ||
&& allFilesInDirectory[i].getName().startsWith(prefix)) { | ||
candidateListOfLogFiles.add(allFilesInDirectory[i].getAbsolutePath()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you could then keep the File
instance.
|
||
Object[] pathes = candidateListOfLogFiles.toArray(); | ||
Arrays.sort(pathes); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you probably rather should use candidateListOfLogFiles.sort(<Comparator>)
and provide a comparator which compares files by their absolute path.
Arrays.sort(pathes); | ||
try { | ||
for (int i = 0; i < pathes.length - maxHistoryFiles; i++) { | ||
File logFile = new File((String) pathes[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed anymore if you stayed with File and you could use a simpler for-loop syntax.
File logFile = new File((String) pathes[i]); | ||
boolean delFile = logFile.delete(); | ||
if (!delFile) { | ||
throw new IOException("Could not delete Access log file: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems harsh to do. Wouldn't it be better to write a log message here and continue removing log files. Otherwise a single undeletable log will stop log file removal forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend changing the _logger to LOGGER and _resourceBundle to RESOURCE_BUNDLE
jenkins test |
Quick build and test passed! |
PAYARA-2822 Access logs are not beeing purged
Quick build and test passed! |
No description provided.