Move OC_Log_xx to \OC\Log namespace

This commit is contained in:
Roeland Jago Douma 2016-05-02 14:04:58 +02:00
parent adf7e7295e
commit fc82047e26
No known key found for this signature in database
GPG key ID: 1E152838F164D13B
8 changed files with 29 additions and 18 deletions

View file

@ -115,7 +115,7 @@ class Manage extends Command {
* @throws \InvalidArgumentException
*/
protected function validateBackend($backend) {
if (!class_exists('OC_Log_'.$backend)) {
if (!class_exists('OC\\Log\\'.ucfirst($backend))) {
throw new \InvalidArgumentException('Invalid backend');
}
}

View file

@ -73,7 +73,7 @@ class Log implements ILogger {
// FIXME: Add this for backwards compatibility, should be fixed at some point probably
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'));
} else {
$this->logger = $logger;

View file

@ -329,7 +329,7 @@ class Server extends ServerContainer implements IServerContainer {
});
$this->registerService('Logger', function (Server $c) {
$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
$logger = 'OC_Log_' . ucfirst($logClass);
$logger = 'OC\\Log\\' . ucfirst($logClass);
call_user_func(array($logger, 'init'));
return new Log($logger);

View file

@ -23,7 +23,9 @@
* THE SOFTWARE.
*/
class OC_Log_Errorlog {
namespace OC\Log;
class Errorlog {
/**

View file

@ -27,13 +27,15 @@
*
*/
namespace OC\Log;
/**
* logging utilities
*
* Log is saved at data/owncloud.log (on default)
*/
class OC_Log_Owncloud {
class Owncloud {
static protected $logFile;
/**
@ -41,7 +43,7 @@ class OC_Log_Owncloud {
*/
public static function init() {
$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);
/**
@ -72,13 +74,13 @@ class OC_Log_Owncloud {
$format = $config->getValue('logdateformat', 'c');
$logTimeZone = $config->getValue( "logtimezone", 'UTC' );
try {
$timezone = new DateTimeZone($logTimeZone);
} catch (Exception $e) {
$timezone = new DateTimeZone('UTC');
$timezone = new \DateTimeZone($logTimeZone);
} catch (\Exception $e) {
$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) {
$time = new DateTime(null, $timezone);
$time = new \DateTime(null, $timezone);
} else {
// apply timezone if $time is created from UNIX timestamp
$time->setTimezone($timezone);

View file

@ -21,7 +21,9 @@
*
*/
class OC_Log_Syslog {
namespace OC\Log;
class Syslog {
static protected $levels = array(
\OCP\Util::DEBUG => LOG_DEBUG,
\OCP\Util::INFO => LOG_INFO,

View file

@ -102,7 +102,7 @@ class LogSettingsController extends Controller {
* @return StreamResponse
*/
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"');
return $resp;
}

View file

@ -15,12 +15,17 @@
* 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
*/
class Test_Log_Owncloud extends Test\TestCase
class OwncloudTest extends TestCase
{
private $restore_logfile;
private $restore_logdateformat;
@ -32,7 +37,7 @@ class Test_Log_Owncloud extends Test\TestCase
$this->restore_logdateformat = $config->getSystemValue('logdateformat');
$config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest");
OC_Log_Owncloud::init();
Owncloud::init();
}
protected function tearDown() {
$config = \OC::$server->getConfig();
@ -46,7 +51,7 @@ class Test_Log_Owncloud extends Test\TestCase
} else {
$config->deleteSystemValue("restore_logdateformat");
}
OC_Log_Owncloud::init();
Owncloud::init();
parent::tearDown();
}
@ -57,7 +62,7 @@ class Test_Log_Owncloud extends Test\TestCase
# set format & write log line
$config->setSystemValue('logdateformat', 'u');
OC_Log_Owncloud::write('test', 'message', \OCP\Util::ERROR);
Owncloud::write('test', 'message', \OCP\Util::ERROR);
# read log line
$handle = @fopen($config->getSystemValue('logfile'), 'r');