MathiasGrimm\LaravelLogKeeper\Services\LogKeeperService::work PHP Метод

work() публичный Метод

public work ( )
    public function work()
    {
        if (!$this->config['enabled']) {
            $this->logger->warning("Log Keeper can't work because it is disabled");
            return;
        }
        $this->logger->info("Starting Laravel Log Keeper");
        $this->logger->info("Local Retention: {$this->localRetentionDays} days");
        $this->logger->info("Remote Retention: {$this->remoteRetentionDays} days");
        $this->logger->info("Calculated Retention: {$this->remoteRetentionDaysCalculated} days");
        $this->localWork();
        if ($this->config['enabled_remote']) {
            $this->remoteCleanUp();
        } else {
            $this->logger->warning("Laravel Log Keeper is not enabled for remote operations");
        }
    }

Usage Example

 /**
  * @test
  */
 public function it_does_nothing_remotely_if_enabled_remote_is_false()
 {
     $today = Carbon::today();
     $config = config('laravel-log-keeper');
     $config['enabled_remote'] = false;
     $localRepo = new FakeLogsRepo($config);
     $remoteRepo = new FakeLogsRepo($config);
     $days = $config['localRetentionDays'] + 1;
     $localLogs = ['/fake/storage/logs/laravel-2010-01-01.log', "/fake/storage/logs/laravel-today-{$today->toDateString()}.log", "/fake/storage/logs/laravel-{$today->addDays($days)->toDateString()}.log"];
     $localRepo->setLogs($localLogs);
     $remoteRepo->setLogs([]);
     $service = new LogKeeperService($config, $localRepo, $remoteRepo, $this->getLogger());
     $service->work();
     $today = Carbon::today();
     $logs = $localRepo->getLogs();
     $this->assertSame(["laravel-today-{$today->toDateString()}.log"], $logs);
     $this->assertSame([], $remoteRepo->getCompressed());
 }