Skip to content

Commit 0fb6c87

Browse files
committed
create rotate file on the fly
1 parent d797356 commit 0fb6c87

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.Properties;
@@ -302,9 +299,31 @@ private RequestLog createRequestLog() {
302299
log.setAppend(true);
303300
log.setLogTimeZone("GMT");
304301
log.setLogLatency(true);
302+
createRotateFile(logPath);
305303
return log;
306304
}
307305

306+
private void createRotateFile(File logPath) {
307+
String rotatefile = "/etc/logrotate/access";
308+
String fileContents = logPath.getAbsolutePath() + " {\n"
309+
+ " copytruncate"
310+
+ " daily"
311+
+ " rotate 14"
312+
+ " compress"
313+
+ " missingok"
314+
+ " create 0644 cloud cloud"
315+
+ "}";
316+
File rotateConfigFile = new File(rotatefile);
317+
try {
318+
FileWriter fw = new FileWriter(rotateConfigFile);
319+
fw.write(fileContents);
320+
fw.close();
321+
} catch (IOException e) {
322+
// log but continue without rotate (for now)
323+
LOG.warn("no way to rotate access log, continuing as is");
324+
}
325+
}
326+
308327
private URL getResource(String aResource) {
309328
return Thread.currentThread().getContextClassLoader().getResource(aResource);
310329
}

0 commit comments

Comments
 (0)