Created
September 5, 2018 09:24
-
-
Save dusta/a8538b7301ee2c5a5c0f17160e33c9f5 to your computer and use it in GitHub Desktop.
Dframe\ActivityLog PSR-3 adapter
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
<?php | |
/** | |
* PSR-3 Adapter for Dframe/activityLog | |
*/ | |
namespace Dframe\ActivityLog\Helper; | |
use Dframe\ActivityLog\Activity; | |
use Psr\Log\AbstractLogger; | |
/** | |
* @author Sławomir Kaleta | |
* Class Logger | |
* @package Dframe\activityLog | |
*/ | |
class Psr3Adapter extends AbstractLogger | |
{ | |
/** | |
* @var object | |
*/ | |
protected $driver; | |
/** | |
* Psr3Adapter constructor. | |
* | |
* @param $driver | |
*/ | |
public function __construct($driver) | |
{ | |
$this->driver = $driver; | |
} | |
/** | |
* @param mixed $level | |
* @param string $message | |
* @param array $context | |
* | |
*/ | |
public function log($level, $message, array $context = []) | |
{ | |
if (!$entity = $this->driver->config['templates'][$level]) { | |
throw new \Exception('Invalid \Psr\Log\LogLevel'); | |
} | |
$log = (new Activity($this->driver, $context['loggedId'] ?? '')); | |
$log->log('system')->entity($entity, [$message])->push(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment