Skip to content

Instantly share code, notes, and snippets.

@AdnanHussainTurki
Created November 14, 2019 22:36
Show Gist options
  • Save AdnanHussainTurki/83cc31354321cd3d90a7c134edfc6378 to your computer and use it in GitHub Desktop.
Save AdnanHussainTurki/83cc31354321cd3d90a7c134edfc6378 to your computer and use it in GitHub Desktop.
<?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