feat : 오류 발생시 슬랙으로 전송
This commit is contained in:
37
app/Exceptions/Handler.php
Normal file
37
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
public function report(Throwable $e): void
|
||||
{
|
||||
if (app()->environment('local') || app()->environment('production')) {
|
||||
$this->sendSlackException($e);
|
||||
}
|
||||
|
||||
parent::report($e); // 로그는 그대로
|
||||
}
|
||||
|
||||
protected function sendSlackException(Throwable $e): void
|
||||
{
|
||||
try {
|
||||
$url = env('LOG_SLACK_WEBHOOK_URL');
|
||||
|
||||
if (!$url) return;
|
||||
|
||||
Http::post($url, [
|
||||
'text' => "*🚨 Laravel 예외 발생!*\n" .
|
||||
"• 메시지: `{$e->getMessage()}`\n" .
|
||||
"• 위치: `{$e->getFile()}:{$e->getLine()}`\n" .
|
||||
"• 시간: " . now()->toDateTimeString()
|
||||
]);
|
||||
} catch (Throwable $ex) {
|
||||
logger()->error('슬랙 전송 실패', ['message' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user