Merge pull request #2951 from nextcloud/handle-nextcloud-log-type-gracefully
Handle log_type "nextcloud" more gracefully
This commit is contained in:
commit
a90cbb0f09
|
@ -106,12 +106,8 @@ class Log implements ILogger {
|
||||||
|
|
||||||
// FIXME: Add this for backwards compatibility, should be fixed at some point probably
|
// FIXME: Add this for backwards compatibility, should be fixed at some point probably
|
||||||
if($logger === null) {
|
if($logger === null) {
|
||||||
// TODO: Drop backwards compatibility for config in the future
|
|
||||||
$logType = $this->config->getValue('log_type', 'file');
|
$logType = $this->config->getValue('log_type', 'file');
|
||||||
if($logType==='owncloud') {
|
$this->logger = static::getLogClass($logType);
|
||||||
$logType = 'file';
|
|
||||||
}
|
|
||||||
$this->logger = 'OC\\Log\\'.ucfirst($logType);
|
|
||||||
call_user_func(array($this->logger, 'init'));
|
call_user_func(array($this->logger, 'init'));
|
||||||
} else {
|
} else {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
@ -327,4 +323,26 @@ class Log implements ILogger {
|
||||||
$msg .= ': ' . json_encode($exception);
|
$msg .= ': ' . json_encode($exception);
|
||||||
$this->error($msg, $context);
|
$this->error($msg, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $logType
|
||||||
|
* @return string
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public static function getLogClass($logType) {
|
||||||
|
switch (strtolower($logType)) {
|
||||||
|
case 'errorlog':
|
||||||
|
return \OC\Log\Errorlog::class;
|
||||||
|
case 'syslog':
|
||||||
|
return \OC\Log\Syslog::class;
|
||||||
|
case 'file':
|
||||||
|
return \OC\Log\File::class;
|
||||||
|
|
||||||
|
// Backwards compatibility for old and fallback for unknown log types
|
||||||
|
case 'owncloud':
|
||||||
|
case 'nextcloud':
|
||||||
|
default:
|
||||||
|
return \OC\Log\File::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,9 +419,8 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
$this->registerService('Logger', function (Server $c) {
|
$this->registerService('Logger', function (Server $c) {
|
||||||
$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'file');
|
$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
|
||||||
// TODO: Drop backwards compatibility for config in the future
|
$logger = Log::getLogClass($logType);
|
||||||
$logger = 'OC\\Log\\' . ucfirst($logClass=='owncloud' ? 'file' : $logClass);
|
|
||||||
call_user_func(array($logger, 'init'));
|
call_user_func(array($logger, 'init'));
|
||||||
|
|
||||||
return new Log($logger);
|
return new Log($logger);
|
||||||
|
|
|
@ -138,4 +138,22 @@ class LoggerTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataGetLogClass() {
|
||||||
|
return [
|
||||||
|
['file', \OC\Log\File::class],
|
||||||
|
['errorlog', \OC\Log\Errorlog::class],
|
||||||
|
['syslog', \OC\Log\Syslog::class],
|
||||||
|
|
||||||
|
['owncloud', \OC\Log\File::class],
|
||||||
|
['nextcloud', \OC\Log\File::class],
|
||||||
|
['foobar', \OC\Log\File::class],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataGetLogClass
|
||||||
|
*/
|
||||||
|
public function testGetLogClass($type, $class) {
|
||||||
|
$this->assertEquals($class, Log::getLogClass($type));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue