-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9541765
commit 2d4e831
Showing
3 changed files
with
20 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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) | ||
{ | ||
|
@@ -107,6 +88,6 @@ public static function toBitrixLevel($level) | |
return $levels[$level]; | ||
} | ||
|
||
return 'UNKNOWN'; | ||
return false; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.