This commit is contained in:
dahn 2026-07-04 14:36:10 +00:00 committed by GitHub
commit 9bf2f428df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 1 deletions

View File

@ -20,8 +20,9 @@ package org.apache.cloudstack;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.util.Properties;
@ -309,9 +310,31 @@ public class ServerDaemon implements Daemon {
log.setAppend(true);
log.setLogTimeZone("GMT");
log.setLogLatency(true);
createRotateFile(logPath);
return log;
}
private void createRotateFile(File logPath) {
String rotatefile = "/etc/logrotate.d/access";
String fileContents = logPath.getAbsolutePath() + " {\n"
+ " copytruncate"
+ " daily"
+ " rotate 14"
+ " compress"
+ " missingok"
+ " create 0644 cloud cloud"
+ "}";
File rotateConfigFile = new File(rotatefile);
try {
FileWriter fw = new FileWriter(rotateConfigFile);
fw.write(fileContents);
fw.close();
} catch (IOException e) {
// log but continue without rotate (for now)
LOG.warn("no way to rotate access log, continuing as is");
}
}
private URL getResource(String aResource) {
return Thread.currentThread().getContextClassLoader().getResource(aResource);
}