nextcloud/lib/log/rotate.php

27 lines
701 B
PHP
Raw Normal View History

2013-07-06 00:24:36 +04:00
<?php
/**
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Log;
class Rotate extends \OC\BackgroundJob\Job {
const LOG_SIZE_LIMIT = 104857600; // 100 MB
public function run($logFile) {
2013-07-06 00:42:17 +04:00
$filesize = @filesize($logFile);
2013-07-06 00:24:36 +04:00
if ($filesize >= self::LOG_SIZE_LIMIT) {
$this->rotate($logFile);
}
}
protected function rotate($logfile) {
2013-07-06 00:42:17 +04:00
$rotatedLogfile = $logfile.'.1';
rename($logfile, $rotatedLogfile);
$msg = 'Log file "'.$logfile.'" was over 100MB, moved to "'.$rotatedLogfile.'"';
2013-07-06 00:24:36 +04:00
\OC_Log::write('OC\Log\Rotate', $msg, \OC_Log::WARN);
}
}