Skip to content

Instantly share code, notes, and snippets.

@dusta
Created September 5, 2018 09:24
Show Gist options
  • Save dusta/a8538b7301ee2c5a5c0f17160e33c9f5 to your computer and use it in GitHub Desktop.
Save dusta/a8538b7301ee2c5a5c0f17160e33c9f5 to your computer and use it in GitHub Desktop.
Dframe\ActivityLog PSR-3 adapter
<?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