You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rotate.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  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. namespace OC\Log;
  9. /**
  10. * This rotates the current logfile to a new name, this way the total log usage
  11. * will stay limited and older entries are available for a while longer.
  12. * For more professional log management set the 'logfile' config to a different
  13. * location and manage that with your own tools.
  14. */
  15. class Rotate extends \OC\BackgroundJob\Job {
  16. private $max_log_size;
  17. public function run($logFile) {
  18. $this->max_log_size = \OC_Config::getValue('log_rotate_size', false);
  19. if ($this->max_log_size) {
  20. $filesize = @filesize($logFile);
  21. if ($filesize >= $this->max_log_size) {
  22. $this->rotate($logFile);
  23. }
  24. }
  25. }
  26. protected function rotate($logfile) {
  27. $rotatedLogfile = $logfile.'.1';
  28. rename($logfile, $rotatedLogfile);
  29. $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"';
  30. \OC_Log::write('OC\Log\Rotate', $msg, \OC_Log::WARN);
  31. }
  32. }