Merge pull request #24404 from owncloud/log_psr4
Move from OC_Log_XX to \OC\Log
This commit is contained in:
commit
3f944753e6
|
@ -115,7 +115,7 @@ class Manage extends Command {
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function validateBackend($backend) {
|
protected function validateBackend($backend) {
|
||||||
if (!class_exists('OC_Log_'.$backend)) {
|
if (!class_exists('OC\\Log\\'.ucfirst($backend))) {
|
||||||
throw new \InvalidArgumentException('Invalid backend');
|
throw new \InvalidArgumentException('Invalid backend');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ 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) {
|
||||||
$this->logger = 'OC_Log_'.ucfirst($this->config->getValue('log_type', 'owncloud'));
|
$this->logger = 'OC\\Log\\'.ucfirst($this->config->getValue('log_type', 'owncloud'));
|
||||||
call_user_func(array($this->logger, 'init'));
|
call_user_func(array($this->logger, 'init'));
|
||||||
} else {
|
} else {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OC_Log_Errorlog {
|
namespace OC\Log;
|
||||||
|
|
||||||
|
class Errorlog {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -27,13 +27,15 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace OC\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* logging utilities
|
* logging utilities
|
||||||
*
|
*
|
||||||
* Log is saved at data/owncloud.log (on default)
|
* Log is saved at data/owncloud.log (on default)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OC_Log_Owncloud {
|
class Owncloud {
|
||||||
static protected $logFile;
|
static protected $logFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +43,7 @@ class OC_Log_Owncloud {
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
$systemConfig = \OC::$server->getSystemConfig();
|
$systemConfig = \OC::$server->getSystemConfig();
|
||||||
$defaultLogFile = $systemConfig->getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log';
|
$defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/owncloud.log';
|
||||||
self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile);
|
self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,13 +74,13 @@ class OC_Log_Owncloud {
|
||||||
$format = $config->getValue('logdateformat', 'c');
|
$format = $config->getValue('logdateformat', 'c');
|
||||||
$logTimeZone = $config->getValue( "logtimezone", 'UTC' );
|
$logTimeZone = $config->getValue( "logtimezone", 'UTC' );
|
||||||
try {
|
try {
|
||||||
$timezone = new DateTimeZone($logTimeZone);
|
$timezone = new \DateTimeZone($logTimeZone);
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$timezone = new DateTimeZone('UTC');
|
$timezone = new \DateTimeZone('UTC');
|
||||||
}
|
}
|
||||||
$time = DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", ""));
|
$time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", ""));
|
||||||
if ($time === false) {
|
if ($time === false) {
|
||||||
$time = new DateTime(null, $timezone);
|
$time = new \DateTime(null, $timezone);
|
||||||
} else {
|
} else {
|
||||||
// apply timezone if $time is created from UNIX timestamp
|
// apply timezone if $time is created from UNIX timestamp
|
||||||
$time->setTimezone($timezone);
|
$time->setTimezone($timezone);
|
|
@ -21,7 +21,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OC_Log_Syslog {
|
namespace OC\Log;
|
||||||
|
|
||||||
|
class Syslog {
|
||||||
static protected $levels = array(
|
static protected $levels = array(
|
||||||
\OCP\Util::DEBUG => LOG_DEBUG,
|
\OCP\Util::DEBUG => LOG_DEBUG,
|
||||||
\OCP\Util::INFO => LOG_INFO,
|
\OCP\Util::INFO => LOG_INFO,
|
|
@ -329,7 +329,7 @@ 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', 'owncloud');
|
$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
|
||||||
$logger = 'OC_Log_' . ucfirst($logClass);
|
$logger = 'OC\\Log\\' . ucfirst($logClass);
|
||||||
call_user_func(array($logger, 'init'));
|
call_user_func(array($logger, 'init'));
|
||||||
|
|
||||||
return new Log($logger);
|
return new Log($logger);
|
||||||
|
|
|
@ -102,7 +102,7 @@ class LogSettingsController extends Controller {
|
||||||
* @return StreamResponse
|
* @return StreamResponse
|
||||||
*/
|
*/
|
||||||
public function download() {
|
public function download() {
|
||||||
$resp = new StreamResponse(\OC_Log_Owncloud::getLogFilePath());
|
$resp = new StreamResponse(\OC\Log\Owncloud::getLogFilePath());
|
||||||
$resp->addHeader('Content-Disposition', 'attachment; filename="owncloud.log"');
|
$resp->addHeader('Content-Disposition', 'attachment; filename="owncloud.log"');
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,17 @@
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Test\Log;
|
||||||
|
|
||||||
|
use OC\Log\Owncloud;
|
||||||
|
use Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Test_Log_Owncloud
|
* Class OwncloudTest
|
||||||
*
|
*
|
||||||
* @group DB
|
* @group DB
|
||||||
*/
|
*/
|
||||||
class Test_Log_Owncloud extends Test\TestCase
|
class OwncloudTest extends TestCase
|
||||||
{
|
{
|
||||||
private $restore_logfile;
|
private $restore_logfile;
|
||||||
private $restore_logdateformat;
|
private $restore_logdateformat;
|
||||||
|
@ -32,7 +37,7 @@ class Test_Log_Owncloud extends Test\TestCase
|
||||||
$this->restore_logdateformat = $config->getSystemValue('logdateformat');
|
$this->restore_logdateformat = $config->getSystemValue('logdateformat');
|
||||||
|
|
||||||
$config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest");
|
$config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest");
|
||||||
OC_Log_Owncloud::init();
|
Owncloud::init();
|
||||||
}
|
}
|
||||||
protected function tearDown() {
|
protected function tearDown() {
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
|
@ -46,7 +51,7 @@ class Test_Log_Owncloud extends Test\TestCase
|
||||||
} else {
|
} else {
|
||||||
$config->deleteSystemValue("restore_logdateformat");
|
$config->deleteSystemValue("restore_logdateformat");
|
||||||
}
|
}
|
||||||
OC_Log_Owncloud::init();
|
Owncloud::init();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +62,7 @@ class Test_Log_Owncloud extends Test\TestCase
|
||||||
|
|
||||||
# set format & write log line
|
# set format & write log line
|
||||||
$config->setSystemValue('logdateformat', 'u');
|
$config->setSystemValue('logdateformat', 'u');
|
||||||
OC_Log_Owncloud::write('test', 'message', \OCP\Util::ERROR);
|
Owncloud::write('test', 'message', \OCP\Util::ERROR);
|
||||||
|
|
||||||
# read log line
|
# read log line
|
||||||
$handle = @fopen($config->getSystemValue('logfile'), 'r');
|
$handle = @fopen($config->getSystemValue('logfile'), 'r');
|
||||||
|
|
Loading…
Reference in New Issue