Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit f2f60a5

Browse files
committed
When calling the delete log endpoint, return the list of logs deleted
1 parent 2306c85 commit f2f60a5

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/DeleteOldLogsTask.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.gson.JsonObject;
66
import com.groupon.seleniumgridextras.config.RuntimeConfig;
77
import com.groupon.seleniumgridextras.tasks.config.TaskDescriptions;
8+
import com.groupon.seleniumgridextras.utilities.json.JsonCodec;
89
import org.apache.log4j.Logger;
910

1011
import java.io.File;
@@ -21,11 +22,23 @@ public DeleteOldLogsTask() {
2122
setRequestType("GET");
2223
setResponseType("json");
2324
setClassname(this.getClass().getCanonicalName().toString());
25+
addResponseDescription(JsonCodec.LOGS_DELETED, "List of logs deleted");
2426
setEnabledInGui(true);
2527
}
2628

2729
@Override
2830
public JsonObject execute() {
31+
32+
List<String> listOfFilesAsString = new LinkedList<String>();
33+
34+
for (File f : deleteOldLogs(
35+
RuntimeConfig.getConfig().getLogMaximumSize(),
36+
RuntimeConfig.getConfig().getLogsDirectory())) {
37+
listOfFilesAsString.add(f.getAbsolutePath());
38+
}
39+
40+
41+
getJsonResponse().addKeyValues(JsonCodec.LOGS_DELETED, listOfFilesAsString);
2942
return getJsonResponse().getJson();
3043
}
3144

@@ -44,9 +57,12 @@ public JsonObject execute(String version) {
4457
public boolean initialize() {
4558

4659
try {
47-
List<File> deletedFiles = deleteOldLogs(RuntimeConfig.getConfig().getLogMaximumSize(), RuntimeConfig.getConfig().getLogsDirectory());
60+
List<File> deletedFiles = deleteOldLogs(
61+
RuntimeConfig.getConfig().getLogMaximumSize(),
62+
RuntimeConfig.getConfig().getLogsDirectory()
63+
);
4864

49-
for(File log : deletedFiles){
65+
for (File log : deletedFiles) {
5066
logger.info(String.format("Deleted log %s", log.getAbsolutePath()));
5167
}
5268
} catch (Exception error) {
@@ -83,7 +99,7 @@ protected List<File> deleteOldLogs(long bytesLimit, File logDir) {
8399

84100
try {
85101
currentFile.delete();
86-
} catch (Exception e){
102+
} catch (Exception e) {
87103
logger.warn(String.format(
88104
"Error deleting log file %s, error: %s, \n %s",
89105
currentFile.getAbsolutePath(),

SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/utilities/json/JsonCodec.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class JsonCodec {
1515
public static final String TRUE_INT = "1";
1616
public static final String WARNING = "__WARNING__";
1717
public static final String COMMAND = "command";
18+
public static final String LOGS_DELETED = "logs_deleted";
1819

1920
public static class SessionLogging {
2021

0 commit comments

Comments
 (0)