Created
January 11, 2023 23:36
-
-
Save abrudtkuhl/1727f08bf688c28f3f2335e0b3e05fda to your computer and use it in GitHub Desktop.
Logspot Log Driver For Laravel
This file contains hidden or 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 | |
namespace App\Logging; | |
use Illuminate\Log\Events\MessageLogged; | |
use Monolog\Logger; | |
use Logspot\Client; | |
class LogspotDriver | |
{ | |
/** | |
* The Logspot client instance. | |
* | |
* @var \Logspot\Client | |
*/ | |
protected $client; | |
/** | |
* Create a new Logspot driver instance. | |
* | |
* @param \Logspot\Client $client | |
* @return void | |
*/ | |
public function __construct(Client $client) | |
{ | |
$this->client = $client; | |
} | |
/** | |
* Log an event to Logspot. | |
* | |
* @param array $event | |
* @return void | |
*/ | |
public function log(array $event) | |
{ | |
$this->client->log($event['level'], $event['message'], $event['context']); | |
} | |
/** | |
* Register the listener for the MessageLogged event. | |
* | |
* @param \Illuminate\Log\Events\MessageLogged $event | |
* @return void | |
*/ | |
public function listen(MessageLogged $event) | |
{ | |
$this->log($event->record); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment