5
5
import com .google .gson .JsonObject ;
6
6
import com .groupon .seleniumgridextras .config .RuntimeConfig ;
7
7
import com .groupon .seleniumgridextras .tasks .config .TaskDescriptions ;
8
+ import com .groupon .seleniumgridextras .utilities .json .JsonCodec ;
8
9
import org .apache .log4j .Logger ;
9
10
10
11
import java .io .File ;
@@ -21,11 +22,23 @@ public DeleteOldLogsTask() {
21
22
setRequestType ("GET" );
22
23
setResponseType ("json" );
23
24
setClassname (this .getClass ().getCanonicalName ().toString ());
25
+ addResponseDescription (JsonCodec .LOGS_DELETED , "List of logs deleted" );
24
26
setEnabledInGui (true );
25
27
}
26
28
27
29
@ Override
28
30
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 );
29
42
return getJsonResponse ().getJson ();
30
43
}
31
44
@@ -44,9 +57,12 @@ public JsonObject execute(String version) {
44
57
public boolean initialize () {
45
58
46
59
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
+ );
48
64
49
- for (File log : deletedFiles ){
65
+ for (File log : deletedFiles ) {
50
66
logger .info (String .format ("Deleted log %s" , log .getAbsolutePath ()));
51
67
}
52
68
} catch (Exception error ) {
@@ -83,7 +99,7 @@ protected List<File> deleteOldLogs(long bytesLimit, File logDir) {
83
99
84
100
try {
85
101
currentFile .delete ();
86
- } catch (Exception e ){
102
+ } catch (Exception e ) {
87
103
logger .warn (String .format (
88
104
"Error deleting log file %s, error: %s, \n %s" ,
89
105
currentFile .getAbsolutePath (),
0 commit comments