Skip to content

Commit 674f855

Browse files
committed
added logger to backup service
1 parent 9d5b6c3 commit 674f855

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Classes/Service/BackupService.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
use League\Flysystem\Filesystem;
1111
use Neos\Flow\Annotations as Flow;
1212
use Neos\Flow\Exception;
13+
use Neos\Flow\Log\PsrLoggerFactoryInterface;
1314
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
1415
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
1516
use Neos\Utility\Files;
17+
use Psr\Log\LoggerInterface;
1618

1719
/**
1820
* @Flow\Scope(value="singleton")
@@ -45,6 +47,11 @@ class BackupService
4547
*/
4648
protected $persistenceManager;
4749

50+
/**
51+
* @var LoggerInterface#
52+
*/
53+
protected $logger;
54+
4855
public function __construct(ObjectManagerInterface $objectManager)
4956
{
5057
$this->objectManager = $objectManager;
@@ -54,8 +61,12 @@ public function initializeObject()
5461
{
5562
$this->indexService = $this->objectManager->get(BackupIndexService::class);
5663
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
64+
5765
$filesystemFactory = $this->objectManager->get(FilesystemFactory::class);
5866
$this->filesystem = $filesystemFactory->get($this->config['filesystem']['type']);
67+
68+
$loggerFactory = $this->objectManager->get(PsrLoggerFactoryInterface::class);
69+
$this->logger = $loggerFactory->get('backupLogger');
5970
}
6071

6172
public function getBackups(int $start = 0, int $limit = 0): array
@@ -76,6 +87,8 @@ public function deleteBackup(string $name): bool
7687
$this->filesystem->delete($name);
7788
}
7889

90+
$this->logger->info('deleted backup '.$name);
91+
7992
return true;
8093
}
8194

@@ -102,6 +115,7 @@ public function restoreBackup(string $name)
102115
}
103116
// persist all changes from the steps
104117
$this->persistenceManager->persistAll();
118+
$this->logger->info('restored backup '.$name);
105119
}
106120

107121

@@ -136,6 +150,7 @@ public function createBackup()
136150
Files::removeDirectoryRecursively($backupPath);
137151
// update index
138152
$this->indexService->addBackup($backupName, new \DateTime(), $meta);
153+
$this->logger->info('added backup '.$backupName);
139154
}
140155

141156
/**

Configuration/Settings.Log.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Neos:
2+
Flow:
3+
log:
4+
psr3:
5+
'Neos\Flow\Log\PsrLoggerFactory':
6+
backupLogger:
7+
default:
8+
class: Neos\Flow\Log\Backend\FileBackend
9+
options:
10+
logFileURL: '%FLOW_PATH_DATA%Logs/Backup.log'
11+
createParentDirectories: true
12+
severityThreshold: '%LOG_INFO%'
13+
maximumLogFileSize: 10485760
14+
logFilesToKeep: 1

0 commit comments

Comments
 (0)