diff --git a/src/Formatter/BitrixFormatter.php b/src/Formatter/BitrixFormatter.php new file mode 100644 index 0000000..66bf388 --- /dev/null +++ b/src/Formatter/BitrixFormatter.php @@ -0,0 +1,47 @@ + + */ +class BitrixFormatter implements FormatterInterface +{ + /** + * {@inheritdoc} + */ + public function format(array $record) + { + if (!empty($record['context'])) + { + foreach ($record['context'] as $name => $value) + { + $record['message'] .= "
" . $name . ': ' . $value; + } + } + + return $record; + } + + /** + * {@inheritdoc} + */ + public function formatBatch(array $records) + { + $formatted = array(); + + foreach ($records as $record) + { + $formatted[] = $this->format($record); + } + + return $formatted; + } +} diff --git a/src/Handler/BitrixHandler.php b/src/Handler/BitrixHandler.php index f5bc4db..da638eb 100644 --- a/src/Handler/BitrixHandler.php +++ b/src/Handler/BitrixHandler.php @@ -9,6 +9,7 @@ use Monolog\Handler\AbstractProcessingHandler; use Monolog\Logger; +use Bex\Monolog\Formatter\BitrixFormatter; use Bitrix\Main\ArgumentNullException; /** @@ -36,6 +37,9 @@ public function __construct($event = null, $module = null, $level = Logger::DEBU $this->module = $module; } + /** + * {@inheritdoc} + */ protected function write(array $record) { \CEventLog::Log( @@ -62,6 +66,14 @@ public function setSite($siteId) { $this->siteId = $siteId; } + + /** + * {@inheritdoc} + */ + protected function getDefaultFormatter() + { + return new BitrixFormatter(); + } /** * Converts Monolog levels to Bitrix ones if necessary.