first commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
abstract class stTaskLogger implements stTaskLoggerInterface
|
||||
{
|
||||
const TYPE_INFO = 0;
|
||||
const TYPE_WARNING = 1;
|
||||
const TYPE_ERROR = 2;
|
||||
|
||||
public function log(int $type, string $message, ?array $messageParams = null): stTaskLoggerInterface
|
||||
{
|
||||
$this->dispatcher->notify(new sfEvent($this, 'task.logger.log', array(
|
||||
'task' => $this->task,
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
'message_params' => $messageParams
|
||||
)));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function info(string $message, array $messageParams = null): stTaskLoggerInterface
|
||||
{
|
||||
return $this->log(self::TYPE_INFO, $message, $messageParams);
|
||||
}
|
||||
|
||||
public function error(string $message, array $messageParams = null): stTaskLoggerInterface
|
||||
{
|
||||
return $this->log(self::TYPE_ERROR, $message, $messageParams);
|
||||
}
|
||||
|
||||
public function warning(string $message, array $messageParams = null): stTaskLoggerInterface
|
||||
{
|
||||
return $this->log(self::TYPE_WARNING, $message, $messageParams);
|
||||
}
|
||||
|
||||
public function exception(Throwable $e): stTaskLoggerInterface
|
||||
{
|
||||
$this->error('%message% w linii %line% w pliku %file%:%trace%', array(
|
||||
'%message%' => $e->getMessage(),
|
||||
'%line%' => $e->getLine(),
|
||||
'%file%' => $e->getFile(),
|
||||
"%trace%" => "\n".$e->getTraceAsString(),
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
interface stTaskLoggerInterface
|
||||
{
|
||||
public function log(int $type, string $message, array $messageParams = null): stTaskLoggerInterface;
|
||||
public function info(string $message, array $messageParams = null): stTaskLoggerInterface;
|
||||
public function error(string $message, array $messageParams = null): stTaskLoggerInterface;
|
||||
public function warning(string $message, array $messageParams = null): stTaskLoggerInterface;
|
||||
public function exception(Throwable $e): stTaskLoggerInterface;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class stTaskPropelLogger extends stTaskLogger
|
||||
{
|
||||
/**
|
||||
* Instancja modelu Task
|
||||
*
|
||||
* @var Task
|
||||
*/
|
||||
protected $task;
|
||||
|
||||
/**
|
||||
* Undocumented variable
|
||||
*
|
||||
* @var stEventDispatcher
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Task $task Instancja modelu Task
|
||||
*/
|
||||
public function __construct(Task $task, stEventDispatcher $dispatcher)
|
||||
{
|
||||
$this->task = $task;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
public function log(int $type, string $message, array $messageParams = null): stTaskLoggerInterface
|
||||
{
|
||||
$log = new TaskLog();
|
||||
$log->setType($type);
|
||||
$log->setTask($this->task);
|
||||
$log->setMessage($messageParams ? '@'.serialize(array($message, $messageParams)) : $message);
|
||||
$log->save();
|
||||
|
||||
return parent::log($type, $message, $messageParams);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user