diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-04-25 17:42:14 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-04-26 12:10:53 +0200 |
commit | b841a477c6b96a13ea061df3fc622c3067514bf2 (patch) | |
tree | c0bb6e6aa539323f187aa03ed67b52b8dfb8b4ad /lib/private/Log | |
parent | ab7a4b869397a5bc267a9f10b42654b35bbe1af6 (diff) | |
download | nextcloud-server-b841a477c6b96a13ea061df3fc622c3067514bf2.tar.gz nextcloud-server-b841a477c6b96a13ea061df3fc622c3067514bf2.zip |
log to $datadir/audit.log by default and add rotation
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private/Log')
-rw-r--r-- | lib/private/Log/Rotate.php | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/lib/private/Log/Rotate.php b/lib/private/Log/Rotate.php index 48b96c98a8d..cc41c804ad3 100644 --- a/lib/private/Log/Rotate.php +++ b/lib/private/Log/Rotate.php @@ -24,7 +24,7 @@ */ namespace OC\Log; -use OCP\ILogger; +use OCP\Log\RotationTrait; /** * This rotates the current logfile to a new name, this way the total log usage @@ -33,23 +33,17 @@ use OCP\ILogger; * location and manage that with your own tools. */ class Rotate extends \OC\BackgroundJob\Job { - private $max_log_size; + use RotationTrait; + public function run($dummy) { $systemConfig = \OC::$server->getSystemConfig(); - $logFile = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'); - $this->max_log_size = \OC::$server->getConfig()->getSystemValue('log_rotate_size', 100 * 1024 * 1024); - if ($this->max_log_size) { - $filesize = @filesize($logFile); - if ($filesize >= $this->max_log_size) { - $this->rotate($logFile); - } - } - } + $this->filePath = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'); - protected function rotate($logfile) { - $rotatedLogfile = $logfile.'.1'; - rename($logfile, $rotatedLogfile); - $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"'; - \OCP\Util::writeLog(Rotate::class, $msg, ILogger::WARN); + $this->maxSize = \OC::$server->getConfig()->getSystemValue('log_rotate_size', 100 * 1024 * 1024); + if($this->shouldRotateBySize()) { + $rotatedFile = $this->rotate(); + $msg = 'Log file "'.$this->filePath.'" was over '.$this->maxSize.' bytes, moved to "'.$rotatedFile.'"'; + \OC::$server->getLogger()->warning($msg, ['app' => Rotate::class]); + } } } |