]> source.dussan.org Git - nextcloud-server.git/commitdiff
Only enable logrotate when configured. Also rotate size is settable.
authorBart Visscher <bartv@thisnet.nl>
Wed, 28 Aug 2013 15:41:27 +0000 (17:41 +0200)
committerBart Visscher <bartv@thisnet.nl>
Wed, 28 Aug 2013 15:41:27 +0000 (17:41 +0200)
config/config.sample.php
lib/base.php
lib/log/rotate.php

index 24ba541ac5c8d5f268df6b66db305a0aafc42bb4..f5cb33732f840d038f6be31206225a0d59aba4fd 100644 (file)
@@ -141,10 +141,22 @@ $CONFIG = array(
 /* Loglevel to start logging at. 0=DEBUG, 1=INFO, 2=WARN, 3=ERROR (default is WARN) */
 "loglevel" => "",
 
+/* date format to be used while writing to the owncloud logfile */
+'logdateformat' => 'F d, Y H:i:s',
+
 /* Append all database queries and parameters to the log file.
  (watch out, this option can increase the size of your log file)*/
 "log_query" => false,
 
+/*
+ * Configure the size in bytes log rotation should happen, 0 or false disables the rotation.
+ * This rotates the current owncloud logfile to a new name, this way the total log usage
+ * will stay limited and older entries are available for a while longer. The
+ * total disk usage is twice the configured size.
+ * WARNING: When you use this, the log entries will eventually be lost.
+ */
+'log_rotate_size' => false, // 104857600, // 100 MiB
+
 /* Lifetime of the remember login cookie, default is 15 days */
 "remember_login_cookie_lifetime" => 60*60*24*15,
 
@@ -189,7 +201,4 @@ $CONFIG = array(
 'customclient_desktop' => '', //http://owncloud.org/sync-clients/
 'customclient_android' => '', //https://play.google.com/store/apps/details?id=com.owncloud.android
 'customclient_ios' => '', //https://itunes.apple.com/us/app/owncloud/id543672169?mt=8
-
-// date format to be used while writing to the owncloud logfile
-'logdateformat' => 'F d, Y H:i:s'
 );
index f45012bb83c3f51f31bf0ba6510913b9624f2567..2e6a37c9f4e854bac44e89c8579283669f03c090 100644 (file)
@@ -557,7 +557,8 @@ class OC {
         * register hooks for the cache
         */
        public static function registerLogRotate() {
-               if (OC_Config::getValue('installed', false)) { //don't try to do this before we are properly setup
+               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');
index 41ef2ea299c71510b63c5ddf9a3279ed09ccdbde..b620f0be15cbd72ef7f7098fb2a5c719cad34940 100644 (file)
@@ -10,24 +10,26 @@ 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. The
- * total disk usage is twice LOG_SIZE_LIMIT.
+ * 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 {
-       const LOG_SIZE_LIMIT = 104857600; // 100 MiB
+       private $max_log_size;
        public function run($logFile) {
-               $filesize = @filesize($logFile);
-               if ($filesize >= self::LOG_SIZE_LIMIT) {
-                       $this->rotate($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 100MB, moved to "'.$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);
        }
 }