Add namespace.

This commit is contained in:
2014-06-02 18:58:49 +04:00
parent aec1a60985
commit 1ba341b064
159 changed files with 265 additions and 264 deletions

26
Logger/CliLogger.php Normal file
View File

@ -0,0 +1,26 @@
<?php namespace Majestic\Logger;
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage Logger
* @since 21-11-2011
* @user: agrebnev
*/
class CliLogger extends Logger
{
protected function concreteLog($message)
{
// Заменяем окончания строк на их символы
$message = str_replace(array("\r", "\n"), array('\r', '\n'), $message);
$out = $this->generateOutString($message);
print($out);
}
protected function generateOutString($message)
{
return microtime(true) . " \t: " . $this->pid . trim($message) . PHP_EOL;
}
}

53
Logger/FileLogger.php Normal file
View File

@ -0,0 +1,53 @@
<?php namespace Majestic\Logger;
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage Logger
* @since 21-11-2011
* @user: agrebnev
*/
class FileLogger extends Logger
{
protected $file_path = '';
/**
* @var resource
*/
protected $handler = null;
protected function __construct()
{
$this->file_path = \Majestic\Config::get('Logger')->filepath;
}
protected function generateOutString($message)
{
return microtime(true) . " \t: " . $this->pid . trim($message) . "\r\n";
}
protected function concreteLog($message)
{
$out = $this->generateOutString($message);
if (!$this->handler) {
$this->handler = @fopen($this->file_path, "a");
if (!$this->handler) {
throw new \Majestic\Exception\GeneralException('Could not open file ' . $this->file_path);
}
}
fwrite($this->handler, $out);
}
public function __destruct()
{
if ($this->handler) {
if (fclose($this->handler)) {
$this->handler = null;
}
}
}
}

63
Logger/Logger.php Normal file
View File

@ -0,0 +1,63 @@
<?php namespace Majestic\Logger;
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage Logger
* @since 21-11-2011
* @user: agrebnev
*/
abstract class Logger
{
protected static $_instance = null;
/**
* pid текущего процесса
* @var string
*/
protected $pid = '';
protected function __construct()
{
}
/**
* @static
* @return Logger
*/
public static function getInstance()
{
if (static::$_instance === null) {
//$class = get_called_class();
$class = \Majestic\Config::get('Logger')->logger;
static::$_instance = new $class();
}
return static::$_instance;
}
/**
* Вывод лога
* @param string $message Сообщение
*/
public function log($message)
{
if (\Majestic\Config::get('LOGGING')) {
$this->concreteLog($message);
}
}
/**
* Установить pid текущего процесса для вывода в лог
* @param int $pid
*/
public function setPid($pid)
{
if (!empty($pid)) {
$this->pid = ' <' . $pid . '> ';
}
}
abstract protected function concreteLog($message);
}