diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2017-01-11 08:14:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-11 08:14:24 +0100 |
commit | a90cbb0f094f0f418c0e6e78dcd406d34f7b3bd2 (patch) | |
tree | 66e8767a3bc1af9aaff0e6c443b2c8d24bf2d123 | |
parent | 40239decb1b36f1daff53710e01d81e18c24f4fc (diff) | |
parent | 7fa063ceca5d78741c47f645c6dfdf65e4be7330 (diff) | |
download | nextcloud-server-a90cbb0f094f0f418c0e6e78dcd406d34f7b3bd2.tar.gz nextcloud-server-a90cbb0f094f0f418c0e6e78dcd406d34f7b3bd2.zip |
Merge pull request #2951 from nextcloud/handle-nextcloud-log-type-gracefully
Handle log_type "nextcloud" more gracefully
-rw-r--r-- | lib/private/Log.php | 28 | ||||
-rw-r--r-- | lib/private/Server.php | 5 | ||||
-rw-r--r-- | tests/lib/LoggerTest.php | 18 |
3 files changed, 43 insertions, 8 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index ef1b70d3cb9..fddd3593127 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -106,12 +106,8 @@ class Log implements ILogger { // FIXME: Add this for backwards compatibility, should be fixed at some point probably if($logger === null) { - // TODO: Drop backwards compatibility for config in the future $logType = $this->config->getValue('log_type', 'file'); - if($logType==='owncloud') { - $logType = 'file'; - } - $this->logger = 'OC\\Log\\'.ucfirst($logType); + $this->logger = static::getLogClass($logType); call_user_func(array($this->logger, 'init')); } else { $this->logger = $logger; @@ -327,4 +323,26 @@ class Log implements ILogger { $msg .= ': ' . json_encode($exception); $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; + } + } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 6888c492910..d88a687bbc4 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -419,9 +419,8 @@ class Server extends ServerContainer implements IServerContainer { ); }); $this->registerService('Logger', function (Server $c) { - $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'file'); - // TODO: Drop backwards compatibility for config in the future - $logger = 'OC\\Log\\' . ucfirst($logClass=='owncloud' ? 'file' : $logClass); + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); + $logger = Log::getLogClass($logType); call_user_func(array($logger, 'init')); return new Log($logger); diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php index abb9deebd55..da9cedc9f56 100644 --- a/tests/lib/LoggerTest.php +++ b/tests/lib/LoggerTest.php @@ -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)); + } } |