1
0

Rotate.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Log;
  8. use OCP\IConfig;
  9. use OCP\Log\RotationTrait;
  10. use Psr\Log\LoggerInterface;
  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 \OCP\BackgroundJob\Job {
  18. use RotationTrait;
  19. public function run($argument): void {
  20. $config = \OCP\Server::get(IConfig::class);
  21. $this->filePath = $config->getSystemValueString('logfile', $config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log');
  22. $this->maxSize = $config->getSystemValueInt('log_rotate_size', 100 * 1024 * 1024);
  23. if ($this->shouldRotateBySize()) {
  24. $rotatedFile = $this->rotate();
  25. $msg = 'Log file "'.$this->filePath.'" was over '.$this->maxSize.' bytes, moved to "'.$rotatedFile.'"';
  26. \OCP\Server::get(LoggerInterface::class)->info($msg, ['app' => Rotate::class]);
  27. }
  28. }
  29. }