Skip to content

Commit

Permalink
Alfa version
Browse files Browse the repository at this point in the history
  • Loading branch information
niksamokhvalov committed Nov 25, 2015
1 parent 9541765 commit 2d4e831
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 152 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": ">=5.3",
"monolog/monolog": "1"
"monolog/monolog": "1.*"
},
"autoload": {
"psr-4": {"Bex\\Monolog\\": "src/"}
Expand Down
57 changes: 19 additions & 38 deletions src/Handler/BitrixHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@

use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Monolog\Processor\WebProcessor;
use Bex\Monolog\Processor\BitrixProcessor;
use Bitrix\Main\ArgumentNullException;

/**
* @author Nik Samokhvalov <[email protected]>
*/
class BitrixHandler extends AbstractProcessingHandler
{
private $event;
private $module;
protected $event;
protected $module;
protected $siteId;

/**
* @param string $event Type of event in the event log.
Expand All @@ -33,61 +32,43 @@ public function __construct($event = null, $module = null, $level = Logger::DEBU
{
parent::__construct($level, $bubble);

$this->setEvent($event);
$this->setModule($module);
$this->pushProcessor(new WebProcessor());
$this->pushProcessor(new BitrixProcessor());
$this->event = $event;
$this->module = $module;
}

protected function write(array $record)
{
\CEventLog::Add(array(
'SEVERITY' => static::toBitrixLevel($record['level']),
'AUDIT_TYPE_ID' => $this->getEvent(),
'MODULE_ID' => $this->getModule(),
'ITEM_ID' => isset($record['context']['ITEM_ID']) ? $record['context']['ITEM_ID'] : 'UNKNOWN',
'REMOTE_ADDR' => $record['extra']['ip'],
'USER_AGENT' => $record['extra']['user_agent'],
'REQUEST_URI' => $record['extra']['url'],
'SITE_ID' => $record['extra']['site_id'],
'USER_ID' => $record['extra']['user_id'],
'GUEST_ID' => $record['extra']['guest_id'],
'DESCRIPTION' => $record['message'],
));
\CEventLog::Log(
static::toBitrixLevel($record['level']),
$this->event,
$this->module,
(isset($record['context']['ITEM_ID'])) ? $record['context']['ITEM_ID'] : null,
$record['message'],
$this->siteId
);
}

public function setEvent($event)
{
$this->event = $event;
}

/**
* @return string
*/
public function getEvent()
{
return ($this->event) ? $this->event : 'UNKNOWN';
}

public function setModule($module)
{
$this->module = $module;
}

/**
* @return string
*/
public function getModule()
public function setSite($siteId)
{
return ($this->module) ? $this->module: 'UNKNOWN';
$this->siteId = $siteId;
}

/**
* Converts PSR-3 levels to Bitrix ones if necessary.
* Converts Monolog levels to Bitrix ones if necessary.
*
* @param int $level Level number.
*
* @return string
* @return string|bool
*/
public static function toBitrixLevel($level)
{
Expand All @@ -107,6 +88,6 @@ public static function toBitrixLevel($level)
return $levels[$level];
}

return 'UNKNOWN';
return false;
}
}
113 changes: 0 additions & 113 deletions src/Processor/BitrixProcessor.php

This file was deleted.

0 comments on commit 2d4e831

Please sign in to comment.