for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Yep\WorkflowLogger\Formatter;
use Yep\WorkflowLogger\ContextDumper\DumperInterface;
use Yep\WorkflowLogger\Record;
/**
* Class StandardFormatter
*
* @package Yep\WorkflowLogger\Formatter
* @author Martin Zeman (Zemistr) <[email protected]>
*/
class StandardFormatter implements FormatterInterface
{
const FORMAT = "[%datetime%] %level%: %message%\n%contextPlaceholder%";
const CONTEXT_FORMAT = "Context:\n%context%\n";
const DATETIME_FORMAT = 'Y-m-d H:i:s.u';
* @var DumperInterface
protected $dumper;
public function __construct(DumperInterface $dumper)
$this->dumper = $dumper;
}
protected function prepareContextPart(Record $record)
$context = $record->getContext();
if (empty($context)) {
return '';
return strtr(
static::CONTEXT_FORMAT,
[
'%context%' => $this->dumper->dump($context),
]
);
public function format(Record $record)
$string = strtr(
static::FORMAT,
'%datetime%' => $record->getDatetime()->format(
static::DATETIME_FORMAT
),
'%level%' => $record->getLevel(),
'%message%' => $record->getMessage(),
'%contextPlaceholder%' => $this->prepareContextPart($record),
return $string;