Skip to content

Commit

Permalink
Bitrix formatter. Work in progress…
Browse files Browse the repository at this point in the history
  • Loading branch information
niksamokhvalov committed Nov 26, 2015
1 parent 832909d commit 2f0ecee
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Formatter/BitrixFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @link https://github.com/bitrix-expert/niceaccess
* @copyright Copyright © 2015 Nik Samokhvalov
* @license MIT
*/

namespace Bex\Monolog\Formatter;

use Monolog\Formatter\FormatterInterface;

/**
* @author Nik Samokhvalov <[email protected]>
*/
class BitrixFormatter implements FormatterInterface
{
/**
* {@inheritdoc}
*/
public function format(array $record)
{
if (!empty($record['context']))
{
foreach ($record['context'] as $name => $value)
{
$record['message'] .= "<br><b>" . $name . '</b>: ' . $value;
}
}

return $record;
}

/**
* {@inheritdoc}
*/
public function formatBatch(array $records)
{
$formatted = array();

foreach ($records as $record)
{
$formatted[] = $this->format($record);
}

return $formatted;
}
}
12 changes: 12 additions & 0 deletions src/Handler/BitrixHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Bex\Monolog\Formatter\BitrixFormatter;
use Bitrix\Main\ArgumentNullException;

/**
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down

0 comments on commit 2f0ecee

Please sign in to comment.