Merge pull request #901 from jonnybarnes/develop

MTM Add Flare support
This commit is contained in:
Jonny Barnes 2023-06-09 14:15:30 +01:00 committed by GitHub
commit 73bc0b5338
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 1760 additions and 1772 deletions

View file

@ -83,6 +83,7 @@ APP_LOG=daily
SESSION_SECURE_COOKIE=true
LOG_SLACK_WEBHOOK_URL=
FLARE_KEY=
FONT_LINK=

View file

@ -63,5 +63,8 @@ APP_LOG=daily
SECURE_SESSION_COOKIE=true
LOG_SLACK_WEBHOOK_URL=
FLARE_KEY=
FONT_LINK=
BRIDGY_MASTODON_TOKEN=

View file

@ -2,90 +2,29 @@
namespace App\Exceptions;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Facades\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;
/**
* @codeCoverageIgnore
*/
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, class-string<\Throwable>>
* @var array<int, string>
*/
protected $dontReport = [
NotFoundHttpException::class,
ModelNotFoundException::class,
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @throws Exception
* @throws Throwable
* Register the exception handling callbacks for the application.
*/
public function report(Throwable $e): void
public function register(): void
{
parent::report($e);
if (config('logging.slack') && $this->shouldReport($e)) {
$guzzle = new Client([
'headers' => [
'Content-Type' => 'application/json',
],
]);
$exceptionName = get_class($e) ?? 'Unknown Exception';
$title = $exceptionName . ': ' . $e->getMessage();
$guzzle->post(
config('logging.slack'),
[
'body' => json_encode([
'attachments' => [[
'fallback' => 'There was an exception.',
'pretext' => 'There was an exception.',
'color' => '#d00000',
'author_name' => app()->environment(),
'author_link' => config('app.url'),
'fields' => [[
'title' => $title,
'value' => request()->method() . ' ' . request()->fullUrl(),
]],
'ts' => time(),
]],
]),
]
);
}
}
/**
* Render an exception into an HTTP response.
*
* @param Request $request
* @return Response
*
* @throws Throwable
*/
public function render($request, Throwable $throwable)
{
if ($throwable instanceof TokenMismatchException) {
Route::getRoutes()->match($request);
}
return parent::render($request, $throwable);
$this->reportable(function (Throwable $e) {
//
});
}
}

View file

@ -30,6 +30,7 @@
"league/flysystem-aws-s3-v3": "^3.0",
"mf2/mf2": "~0.3",
"spatie/commonmark-highlighter": "^3.0",
"spatie/laravel-ignition": "^2.1",
"symfony/html-sanitizer": "^6.1"
},
"require-dev": {
@ -44,7 +45,6 @@
"nunomaduro/collision": "^7.0",
"phpunit/php-code-coverage": "^10.0",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0",
"spatie/laravel-ray": "^1.12",
"vimeo/psalm": "^5.0"
},

1174
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -3,6 +3,7 @@
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
use Monolog\Processor\PsrLogMessageProcessor;
return [
@ -53,7 +54,7 @@ return [
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
'channels' => ['daily', 'flare'],
'ignore_exceptions' => false,
],
@ -61,6 +62,7 @@ return [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
],
'daily' => [
@ -68,6 +70,7 @@ return [
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
'replace_placeholders' => true,
],
'slack' => [
@ -76,6 +79,7 @@ return [
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => env('LOG_LEVEL', 'critical'),
'replace_placeholders' => true,
],
'papertrail' => [
@ -87,6 +91,7 @@ return [
'port' => env('PAPERTRAIL_PORT'),
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
],
'processors' => [PsrLogMessageProcessor::class],
],
'stderr' => [
@ -97,16 +102,20 @@ return [
'with' => [
'stream' => 'php://stderr',
],
'processors' => [PsrLogMessageProcessor::class],
],
'syslog' => [
'driver' => 'syslog',
'level' => env('LOG_LEVEL', 'debug'),
'facility' => LOG_USER,
'replace_placeholders' => true,
],
'errorlog' => [
'driver' => 'errorlog',
'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
],
'null' => [
@ -117,8 +126,10 @@ return [
'emergency' => [
'path' => storage_path('logs/laravel.log'),
],
'flare' => [
'driver' => 'flare',
],
],
'slack' => env('LOG_SLACK_WEBHOOK_URL'),
];

2234
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,16 +5,16 @@
"repository": "https://github.com/jonnybarnes/jonnybarnes.uk",
"license": "CC0-1.0",
"devDependencies": {
"@babel/core": "^7.22.1",
"@babel/preset-env": "^7.22.2",
"@csstools/postcss-oklab-function": "^2.2.2",
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"@csstools/postcss-oklab-function": "^2.2.3",
"autoprefixer": "^10.4.14",
"babel-loader": "^9.1.2",
"browserlist": "^1.0.1",
"compression-webpack-plugin": "^10.0.0",
"css-loader": "^6.8.1",
"cssnano": "^6.0.1",
"eslint": "^8.41.0",
"eslint": "^8.42.0",
"eslint-webpack-plugin": "^4.0.1",
"mini-css-extract-plugin": "^2.7.6",
"postcss": "^8.4.24",
@ -24,11 +24,11 @@
"postcss-loader": "^7.3.2",
"postcss-nesting": "^11.2.2",
"style-loader": "^3.3.3",
"stylelint": "^15.6.2",
"stylelint": "^15.7.0",
"stylelint-config-standard": "^33.0.0",
"stylelint-webpack-plugin": "^4.1.1",
"webpack": "^5.84.1",
"webpack-cli": "^5.1.1"
"webpack": "^5.86.0",
"webpack-cli": "^5.1.4"
},
"scripts": {
"dev": "webpack --mode=development",