]> source.dussan.org Git - nextcloud-server.git/commitdiff
Very simple log rotation
authorBart Visscher <bartv@thisnet.nl>
Fri, 5 Jul 2013 20:24:36 +0000 (22:24 +0200)
committerBart Visscher <bartv@thisnet.nl>
Wed, 28 Aug 2013 15:11:43 +0000 (17:11 +0200)
lib/base.php
lib/log/rotate.php [new file with mode: 0644]

index 0c9fe329b8fe36aa67d55af8121bab74a359ec07..22aed1c566455ec20a2ea05ba305b1f0a88bc2eb 100644 (file)
@@ -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 (file)
index 0000000..d5b970c
--- /dev/null
@@ -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);
+       }
+}