2018-04-24 23:14:00 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2018-06-06 23:40:06 +03:00
|
|
|
* @author Johannes Ernst <jernst@indiecomputing.com>
|
2018-04-24 23:14:00 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-04-24 23:14:00 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Log;
|
|
|
|
|
2018-04-25 03:27:43 +03:00
|
|
|
use OC\Log;
|
2018-04-27 00:54:11 +03:00
|
|
|
use OC\SystemConfig;
|
2018-04-25 03:27:43 +03:00
|
|
|
use OCP\ILogger;
|
2018-04-24 23:14:00 +03:00
|
|
|
use OCP\IServerContainer;
|
2018-04-25 03:27:43 +03:00
|
|
|
use OCP\Log\ILogFactory;
|
|
|
|
use OCP\Log\IWriter;
|
2018-04-24 23:14:00 +03:00
|
|
|
|
2018-04-25 03:27:43 +03:00
|
|
|
class LogFactory implements ILogFactory {
|
2018-04-24 23:14:00 +03:00
|
|
|
/** @var IServerContainer */
|
|
|
|
private $c;
|
2018-04-27 00:54:11 +03:00
|
|
|
/** @var SystemConfig */
|
|
|
|
private $systemConfig;
|
2018-04-24 23:14:00 +03:00
|
|
|
|
2018-04-27 00:54:11 +03:00
|
|
|
public function __construct(IServerContainer $c, SystemConfig $systemConfig) {
|
2018-04-24 23:14:00 +03:00
|
|
|
$this->c = $c;
|
2018-04-27 00:54:11 +03:00
|
|
|
$this->systemConfig = $systemConfig;
|
2018-04-24 23:14:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \OCP\AppFramework\QueryException
|
|
|
|
*/
|
2018-04-25 03:27:43 +03:00
|
|
|
public function get(string $type):IWriter {
|
2018-04-24 23:14:00 +03:00
|
|
|
switch (strtolower($type)) {
|
|
|
|
case 'errorlog':
|
|
|
|
return new Errorlog();
|
|
|
|
case 'syslog':
|
|
|
|
return $this->c->resolve(Syslog::class);
|
2018-06-06 23:40:06 +03:00
|
|
|
case 'systemd':
|
|
|
|
return $this->c->resolve(Systemdlog::class);
|
2018-04-24 23:14:00 +03:00
|
|
|
case 'file':
|
|
|
|
return $this->buildLogFile();
|
|
|
|
|
|
|
|
// Backwards compatibility for old and fallback for unknown log types
|
|
|
|
case 'owncloud':
|
|
|
|
case 'nextcloud':
|
|
|
|
default:
|
2018-04-25 03:27:43 +03:00
|
|
|
return $this->buildLogFile();
|
2018-04-24 23:14:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 03:27:43 +03:00
|
|
|
public function getCustomLogger(string $path):ILogger {
|
|
|
|
$log = $this->buildLogFile($path);
|
2018-04-27 00:54:11 +03:00
|
|
|
return new Log($log, $this->systemConfig);
|
2018-04-25 03:27:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildLogFile(string $logFile = ''):File {
|
2018-04-27 00:54:11 +03:00
|
|
|
$defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT.'/data').'/nextcloud.log';
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($logFile === '') {
|
2018-04-27 00:54:11 +03:00
|
|
|
$logFile = $this->systemConfig->getValue('logfile', $defaultLogFile);
|
2018-04-25 03:27:43 +03:00
|
|
|
}
|
2018-04-24 23:14:00 +03:00
|
|
|
$fallback = $defaultLogFile !== $logFile ? $defaultLogFile : '';
|
|
|
|
|
2018-04-27 00:54:11 +03:00
|
|
|
return new File($logFile, $fallback, $this->systemConfig);
|
2018-04-24 23:14:00 +03:00
|
|
|
}
|
|
|
|
}
|