summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorkondou <kondou@ts.unde.re>2013-08-28 23:21:26 +0200
committerkondou <kondou@ts.unde.re>2013-08-28 23:21:26 +0200
commit0ba498119ca2cdc0705b3ede5adf1dda9073d2ea (patch)
tree12f6559012f435e18b836848cecab2a05235a064 /lib
parentbdf48a6daa8234b307bb7b73a231de5227e10b30 (diff)
parentcebb635955c71895545ce7ff5bad7808b1e22c0e (diff)
downloadnextcloud-server-0ba498119ca2cdc0705b3ede5adf1dda9073d2ea.tar.gz
nextcloud-server-0ba498119ca2cdc0705b3ede5adf1dda9073d2ea.zip
Merge branch 'master' into oc_avatars
Conflicts: 3rdparty
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php16
-rw-r--r--lib/log/rotate.php35
2 files changed, 51 insertions, 0 deletions
diff --git a/lib/base.php b/lib/base.php
index 0c9fe329b8f..2e6a37c9f4e 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -491,6 +491,7 @@ class OC {
self::registerCacheHooks();
self::registerFilesystemHooks();
self::registerShareHooks();
+ self::registerLogRotate();
//make sure temporary files are cleaned up
register_shutdown_function(array('OC_Helper', 'cleanTmp'));
@@ -553,6 +554,21 @@ class OC {
}
/**
+ * register hooks for the cache
+ */
+ public static function registerLogRotate() {
+ if (OC_Config::getValue('installed', false) && OC_Config::getValue('log_rotate_size', false)) {
+ //don't try to do this before we are properly setup
+ // register cache cleanup jobs
+ try { //if this is executed before the upgrade to the new backgroundjob system is completed it will throw an exception
+ \OCP\BackgroundJob::registerJob('OC\Log\Rotate', OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log');
+ } catch (Exception $e) {
+
+ }
+ }
+ }
+
+ /**
* register hooks for the filesystem
*/
public static function registerFilesystemHooks() {
diff --git a/lib/log/rotate.php b/lib/log/rotate.php
new file mode 100644
index 00000000000..bf23ad588b3
--- /dev/null
+++ b/lib/log/rotate.php
@@ -0,0 +1,35 @@
+<?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;
+
+/**
+ * This rotates the current logfile to a new name, this way the total log usage
+ * will stay limited and older entries are available for a while longer.
+ * For more professional log management set the 'logfile' config to a different
+ * location and manage that with your own tools.
+ */
+class Rotate extends \OC\BackgroundJob\Job {
+ private $max_log_size;
+ public function run($logFile) {
+ $this->max_log_size = \OC_Config::getValue('log_rotate_size', false);
+ if ($this->max_log_size) {
+ $filesize = @filesize($logFile);
+ if ($filesize >= $this->max_log_size) {
+ $this->rotate($logFile);
+ }
+ }
+ }
+
+ protected function rotate($logfile) {
+ $rotatedLogfile = $logfile.'.1';
+ rename($logfile, $rotatedLogfile);
+ $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"';
+ \OC_Log::write('OC\Log\Rotate', $msg, \OC_Log::WARN);
+ }
+}