3
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
4
* This file is licensed under the Affero General Public License version 3 or
6
* See the COPYING-README file.
12
* This rotates the current logfile to a new name, this way the total log usage
13
* will stay limited and older entries are available for a while longer.
14
* For more professional log management set the 'logfile' config to a different
15
* location and manage that with your own tools.
17
class Rotate extends \OC\BackgroundJob\Job {
18
private $max_log_size;
19
public function run($logFile) {
20
$this->max_log_size = \OC_Config::getValue('log_rotate_size', false);
21
if ($this->max_log_size) {
22
$filesize = @filesize($logFile);
23
if ($filesize >= $this->max_log_size) {
24
$this->rotate($logFile);
29
protected function rotate($logfile) {
30
$rotatedLogfile = $logfile.'.1';
31
rename($logfile, $rotatedLogfile);
32
$msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"';
33
\OC_Log::write('OC\Log\Rotate', $msg, \OC_Log::WARN);