aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Log/LogFactory.php
diff options
context:
space:
mode:
authorFaraz Samapoor <f.samapoor@gmail.com>2023-06-28 09:23:43 +0330
committerFaraz Samapoor <fsa@adlas.at>2023-06-28 09:29:45 +0330
commit9fa9975bc937b2dd361c742137586284fe6d110d (patch)
treee795ab8e194c9182b49376b13f7c6b12d516fb96 /lib/private/Log/LogFactory.php
parent918aacdf1a71dcee42e73a0da09e5925769ae99e (diff)
downloadnextcloud-server-9fa9975bc937b2dd361c742137586284fe6d110d.tar.gz
nextcloud-server-9fa9975bc937b2dd361c742137586284fe6d110d.zip
Refactors lib/private/Log.
Mainly using PHP8's constructor property promotion. Signed-off-by: Faraz Samapoor <fsa@adlas.at>
Diffstat (limited to 'lib/private/Log/LogFactory.php')
-rw-r--r--lib/private/Log/LogFactory.php58
1 files changed, 19 insertions, 39 deletions
diff --git a/lib/private/Log/LogFactory.php b/lib/private/Log/LogFactory.php
index a5008f5ef77..c395c31eb98 100644
--- a/lib/private/Log/LogFactory.php
+++ b/lib/private/Log/LogFactory.php
@@ -33,57 +33,37 @@ use OCP\Log\IWriter;
use Psr\Log\LoggerInterface;
class LogFactory implements ILogFactory {
- /** @var IServerContainer */
- private $c;
- /** @var SystemConfig */
- private $systemConfig;
-
- public function __construct(IServerContainer $c, SystemConfig $systemConfig) {
- $this->c = $c;
- $this->systemConfig = $systemConfig;
+ public function __construct(
+ private IServerContainer $c,
+ private SystemConfig $systemConfig,
+ ) {
}
/**
* @throws \OCP\AppFramework\QueryException
*/
public function get(string $type):IWriter {
- switch (strtolower($type)) {
- case 'errorlog':
- return new Errorlog($this->systemConfig);
- case 'syslog':
- return $this->c->resolve(Syslog::class);
- case 'systemd':
- return $this->c->resolve(Systemdlog::class);
- case 'file':
- return $this->buildLogFile();
-
- // Backwards compatibility for old and fallback for unknown log types
- case 'owncloud':
- case 'nextcloud':
- default:
- return $this->buildLogFile();
- }
+ return match (strtolower($type)) {
+ 'errorlog' => new Errorlog($this->systemConfig),
+ 'syslog' => $this->c->resolve(Syslog::class),
+ 'systemd' => $this->c->resolve(Systemdlog::class),
+ 'file' => $this->buildLogFile(),
+ default => $this->buildLogFile(),
+ };
}
- public function getCustomLogger(string $path):ILogger {
+ public function getCustomLogger(string $path): ILogger {
$log = $this->buildLogFile($path);
return new Log($log, $this->systemConfig);
}
protected function createNewLogger(string $type, string $tag, string $path): IWriter {
- switch (strtolower($type)) {
- case 'errorlog':
- return new Errorlog($this->systemConfig, $tag);
- case 'syslog':
- return new Syslog($this->systemConfig, $tag);
- case 'systemd':
- return new Systemdlog($this->systemConfig, $tag);
- case 'file':
- case 'owncloud':
- case 'nextcloud':
- default:
- return $this->buildLogFile($path);
- }
+ return match (strtolower($type)) {
+ 'errorlog' => new Errorlog($this->systemConfig, $tag),
+ 'syslog' => new Syslog($this->systemConfig, $tag),
+ 'systemd' => new Systemdlog($this->systemConfig, $tag),
+ default => $this->buildLogFile($path),
+ };
}
public function getCustomPsrLogger(string $path, string $type = 'file', string $tag = 'Nextcloud'): LoggerInterface {
@@ -93,7 +73,7 @@ class LogFactory implements ILogFactory {
);
}
- protected function buildLogFile(string $logFile = ''):File {
+ protected function buildLogFile(string $logFile = ''): File {
$defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT.'/data').'/nextcloud.log';
if ($logFile === '') {
$logFile = $this->systemConfig->getValue('logfile', $defaultLogFile);