Skip to content

Commit 3d0be13

Browse files
committed
create rotate file on the fly
1 parent 0e8b0b8 commit 3d0be13

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

client/src/main/java/org/apache/cloudstack/ServerDaemon.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
//
1919
package org.apache.cloudstack;
2020

21-
import java.io.File;
22-
import java.io.FileInputStream;
23-
import java.io.IOException;
24-
import java.io.InputStream;
21+
import java.io.*;
2522
import java.lang.management.ManagementFactory;
2623
import java.net.URL;
2724
import java.util.Arrays;
@@ -333,9 +330,31 @@ private RequestLog createRequestLog() {
333330
log.setAppend(true);
334331
log.setLogTimeZone("GMT");
335332
log.setLogLatency(true);
333+
createRotateFile(logPath);
336334
return log;
337335
}
338336

337+
private void createRotateFile(File logPath) {
338+
String rotatefile = "/etc/logrotate/access";
339+
String fileContents = logPath.getAbsolutePath() + " {\n"
340+
+ " copytruncate"
341+
+ " daily"
342+
+ " rotate 14"
343+
+ " compress"
344+
+ " missingok"
345+
+ " create 0644 cloud cloud"
346+
+ "}";
347+
File rotateConfigFile = new File(rotatefile);
348+
try {
349+
FileWriter fw = new FileWriter(rotateConfigFile);
350+
fw.write(fileContents);
351+
fw.close();
352+
} catch (IOException e) {
353+
// log but continue without rotate (for now)
354+
LOG.warn("no way to rotate access log, continuing as is");
355+
}
356+
}
357+
339358
private URL getResource(String aResource) {
340359
return Thread.currentThread().getContextClassLoader().getResource(aResource);
341360
}

0 commit comments

Comments
 (0)