Created
November 14, 2019 22:36
-
-
Save AdnanHussainTurki/83cc31354321cd3d90a7c134edfc6378 to your computer and use it in GitHub Desktop.
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 myPHPnotes; | |
use Crummy\Phlack\Phlack; | |
class SlackLogger | |
{ | |
protected $client; | |
function __construct(string $webhook_url) | |
{ | |
$this->client = new Phlack($webhook_url); | |
} | |
public function logError($e) | |
{ | |
$messageBuilder = $this->client->getMessageBuilder(); | |
$messageBuilder | |
->setText("Error Type: " . get_class($e)) | |
->createAttachment() | |
->setTitle($e->getMessage() . "\n" . "File: ".$e->getFile() . "\n" ."Line: " . $e->getLine()) | |
->setText($e->getTrace()) | |
->setColor("#ff0000") | |
->end(); | |
$message = $messageBuilder->create(); | |
return $this->client->send($message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment