public function cleanupLogFiles()
{
// rotate logs
$logs = [PIMCORE_LOG_DEBUG, PIMCORE_LOG_DIRECTORY . "/php.log", PIMCORE_LOG_DIRECTORY . "/redirect.log", PIMCORE_LOG_DIRECTORY . "/legacy-class-names.log", PIMCORE_LOG_DIRECTORY . "/legacy-class-names-admin.log", PIMCORE_LOG_DIRECTORY . "/libreoffice-pdf-convert.log"];
foreach ($logs as $log) {
if (file_exists($log) && filesize($log) > 200000000) {
// archive log (will be cleaned up by maintenance)
rename($log, $log . "-archive-" . date("m-d-Y-H-i"));
\Pimcore\File::put(PIMCORE_LOG_DEBUG, "");
}
}
// archive and cleanup logs
$files = glob(PIMCORE_LOG_DIRECTORY . "/*.log-archive-*");
if (is_array($files)) {
foreach ($files as $file) {
if (filemtime($file) < time() - 86400 * 30) {
// we keep the logs for 30 days
unlink($file);
} elseif (!preg_match("/\\.gz\$/", $file)) {
gzcompressfile($file);
unlink($file);
}
}
}
}