diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-07-05 22:24:36 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-08-28 17:11:43 +0200 |
commit | b5e2842e0049f64b0f7c7ba9ce8b831bd84a0d78 (patch) | |
tree | 936f382972eb941670dee771f140f117e35dbed7 | |
parent | 0c02e1efef76430eea8986697cd9736814fb604a (diff) | |
download | nextcloud-server-b5e2842e0049f64b0f7c7ba9ce8b831bd84a0d78.tar.gz nextcloud-server-b5e2842e0049f64b0f7c7ba9ce8b831bd84a0d78.zip |
Very simple log rotation
-rw-r--r-- | lib/base.php | 1 | ||||
-rw-r--r-- | lib/log/rotate.php | 26 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/base.php b/lib/base.php index 0c9fe329b8f..22aed1c5664 100644 --- a/lib/base.php +++ b/lib/base.php @@ -491,6 +491,7 @@ class OC { self::registerCacheHooks(); self::registerFilesystemHooks(); self::registerShareHooks(); + \OCP\BackgroundJob::registerJob('OC\Log\Rotate', OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log'); //make sure temporary files are cleaned up register_shutdown_function(array('OC_Helper', 'cleanTmp')); diff --git a/lib/log/rotate.php b/lib/log/rotate.php new file mode 100644 index 00000000000..d5b970c1a9e --- /dev/null +++ b/lib/log/rotate.php @@ -0,0 +1,26 @@ +<?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) { + $filesize = filesize($logFile); + if ($filesize >= self::LOG_SIZE_LIMIT) { + $this->rotate($logFile); + } + } + + protected function rotate($logfile) { + $rotated_logfile = $logfile.'.1'; + rename($logfile, $rotated_logfile); + $msg = 'Log file "'.$logfile.'" was over 100MB, moved to "'.$rotated_logfile.'"'; + \OC_Log::write('OC\Log\Rotate', $msg, \OC_Log::WARN); + } +} |