~pvigo/+junk/owncloud-14.04

« back to all changes in this revision

Viewing changes to usr/share/owncloud/lib/private/log/rotate.php

  • Committer: Pablo Vigo
  • Date: 2014-12-15 13:36:46 UTC
  • Revision ID: pvigo@xtec.cat-20141215133646-7d6it90e1dbsijc2
2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
4
 
 * This file is licensed under the Affero General Public License version 3 or
5
 
 * later.
6
 
 * See the COPYING-README file.
7
 
 */
8
 
 
9
 
namespace OC\Log;
10
 
 
11
 
/**
12
 
 * This rotates the current logfile to a new name, this way the total log usage
13
 
 * will stay limited and older entries are available for a while longer.
14
 
 * For more professional log management set the 'logfile' config to a different
15
 
 * location and manage that with your own tools.
16
 
 */
17
 
class Rotate extends \OC\BackgroundJob\Job {
18
 
        private $max_log_size;
19
 
        public function run($logFile) {
20
 
                $this->max_log_size = \OC_Config::getValue('log_rotate_size', false);
21
 
                if ($this->max_log_size) {
22
 
                        $filesize = @filesize($logFile);
23
 
                        if ($filesize >= $this->max_log_size) {
24
 
                                $this->rotate($logFile);
25
 
                        }
26
 
                }
27
 
        }
28
 
 
29
 
        protected function rotate($logfile) {
30
 
                $rotatedLogfile = $logfile.'.1';
31
 
                rename($logfile, $rotatedLogfile);
32
 
                $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"';
33
 
                \OC_Log::write('OC\Log\Rotate', $msg, \OC_Log::WARN);
34
 
        }
35
 
}