Rotate.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Log;
  26. use OCP\Log\RotationTrait;
  27. /**
  28. * This rotates the current logfile to a new name, this way the total log usage
  29. * will stay limited and older entries are available for a while longer.
  30. * For more professional log management set the 'logfile' config to a different
  31. * location and manage that with your own tools.
  32. */
  33. class Rotate extends \OCP\BackgroundJob\Job {
  34. use RotationTrait;
  35. public function run($dummy) {
  36. $systemConfig = \OC::$server->getSystemConfig();
  37. $this->filePath = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log');
  38. $this->maxSize = \OC::$server->getConfig()->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
  39. if ($this->shouldRotateBySize()) {
  40. $rotatedFile = $this->rotate();
  41. $msg = 'Log file "'.$this->filePath.'" was over '.$this->maxSize.' bytes, moved to "'.$rotatedFile.'"';
  42. \OC::$server->getLogger()->warning($msg, ['app' => Rotate::class]);
  43. }
  44. }
  45. }