|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bart Visscher <[email protected]> |
|
6
|
|
|
* @author Morris Jobke <[email protected]> |
|
7
|
|
|
* @author Robin Appelman <[email protected]> |
|
8
|
|
|
* @author Thomas Müller <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* @license AGPL-3.0 |
|
11
|
|
|
* |
|
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
14
|
|
|
* as published by the Free Software Foundation. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OC\Log; |
|
27
|
|
|
use OCP\Log\RotationTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* This rotates the current logfile to a new name, this way the total log usage |
|
31
|
|
|
* will stay limited and older entries are available for a while longer. |
|
32
|
|
|
* For more professional log management set the 'logfile' config to a different |
|
33
|
|
|
* location and manage that with your own tools. |
|
34
|
|
|
*/ |
|
35
|
|
|
class Rotate extends \OC\BackgroundJob\Job { |
|
36
|
|
|
use RotationTrait; |
|
37
|
|
|
|
|
38
|
|
|
public function run($dummy) { |
|
39
|
|
|
$systemConfig = \OC::$server->getSystemConfig(); |
|
40
|
|
|
$this->filePath = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'); |
|
41
|
|
|
|
|
42
|
|
|
$this->maxSize = \OC::$server->getConfig()->getSystemValue('log_rotate_size', 100 * 1024 * 1024); |
|
43
|
|
|
if($this->shouldRotateBySize()) { |
|
44
|
|
|
$rotatedFile = $this->rotate(); |
|
45
|
|
|
$msg = 'Log file "'.$this->filePath.'" was over '.$this->maxSize.' bytes, moved to "'.$rotatedFile.'"'; |
|
46
|
|
|
\OC::$server->getLogger()->warning($msg, ['app' => Rotate::class]); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|