This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/lib/Rails/Log/Formatter/Simple.php

43 lines
1.2 KiB
PHP
Raw Normal View History

2013-10-02 18:14:53 +02:00
<?php
namespace Rails\Log\Formatter;
class Simple extends \Zend\Log\Formatter\Simple
{
const DEFAULT_FORMAT = '%priorityName%: %message% %extra%';
protected $format = '%priorityName%: %message% %extra%';
protected $originalFormat;
public function format($event)
{
$prevFormat = null;
/**
* Hack: write log without priorityName.
*/
if ($event['priorityName'] == 'NONE') {
$this->originalFormat = $this->format;
$this->format = trim(str_replace('%priorityName%', '', $this->format), ': ');
}
/**
* Hack: write log with date.
*/
if (!empty($event['extra']['date'])) {
if (!$this->originalFormat) {
$this->originalFormat = $this->format;
}
$this->format = '[%timestamp%] ' . $this->format;
unset($event['extra']['date']);
}
$ret = parent::format($event);
if ($this->originalFormat) {
$this->format = $this->originalFormat;
$this->originalFormat = null;
}
return $ret;
}
}