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 SESSION_SECURE_COOKIE=true
LOG_SLACK_WEBHOOK_URL= LOG_SLACK_WEBHOOK_URL=
FLARE_KEY=
FONT_LINK= FONT_LINK=

View file

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

View file

@ -2,90 +2,29 @@
namespace App\Exceptions; namespace App\Exceptions;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; 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; use Throwable;
/**
* @codeCoverageIgnore
*/
class Handler extends ExceptionHandler 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 = [ protected $dontFlash = [
NotFoundHttpException::class, 'current_password',
ModelNotFoundException::class, 'password',
'password_confirmation',
]; ];
/** /**
* Report or log an exception. * Register the exception handling callbacks for the application.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @throws Exception
* @throws Throwable
*/ */
public function report(Throwable $e): void public function register(): void
{ {
parent::report($e); $this->reportable(function (Throwable $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);
} }
} }

View file

@ -30,6 +30,7 @@
"league/flysystem-aws-s3-v3": "^3.0", "league/flysystem-aws-s3-v3": "^3.0",
"mf2/mf2": "~0.3", "mf2/mf2": "~0.3",
"spatie/commonmark-highlighter": "^3.0", "spatie/commonmark-highlighter": "^3.0",
"spatie/laravel-ignition": "^2.1",
"symfony/html-sanitizer": "^6.1" "symfony/html-sanitizer": "^6.1"
}, },
"require-dev": { "require-dev": {
@ -44,7 +45,6 @@
"nunomaduro/collision": "^7.0", "nunomaduro/collision": "^7.0",
"phpunit/php-code-coverage": "^10.0", "phpunit/php-code-coverage": "^10.0",
"phpunit/phpunit": "^10.0", "phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0",
"spatie/laravel-ray": "^1.12", "spatie/laravel-ray": "^1.12",
"vimeo/psalm": "^5.0" "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\NullHandler;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler; use Monolog\Handler\SyslogUdpHandler;
use Monolog\Processor\PsrLogMessageProcessor;
return [ return [
@ -53,7 +54,7 @@ return [
'channels' => [ 'channels' => [
'stack' => [ 'stack' => [
'driver' => 'stack', 'driver' => 'stack',
'channels' => ['single'], 'channels' => ['daily', 'flare'],
'ignore_exceptions' => false, 'ignore_exceptions' => false,
], ],
@ -61,6 +62,7 @@ return [
'driver' => 'single', 'driver' => 'single',
'path' => storage_path('logs/laravel.log'), 'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'), 'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
], ],
'daily' => [ 'daily' => [
@ -68,6 +70,7 @@ return [
'path' => storage_path('logs/laravel.log'), 'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'), 'level' => env('LOG_LEVEL', 'debug'),
'days' => 14, 'days' => 14,
'replace_placeholders' => true,
], ],
'slack' => [ 'slack' => [
@ -76,6 +79,7 @@ return [
'username' => 'Laravel Log', 'username' => 'Laravel Log',
'emoji' => ':boom:', 'emoji' => ':boom:',
'level' => env('LOG_LEVEL', 'critical'), 'level' => env('LOG_LEVEL', 'critical'),
'replace_placeholders' => true,
], ],
'papertrail' => [ 'papertrail' => [
@ -87,6 +91,7 @@ return [
'port' => env('PAPERTRAIL_PORT'), 'port' => env('PAPERTRAIL_PORT'),
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
], ],
'processors' => [PsrLogMessageProcessor::class],
], ],
'stderr' => [ 'stderr' => [
@ -97,16 +102,20 @@ return [
'with' => [ 'with' => [
'stream' => 'php://stderr', 'stream' => 'php://stderr',
], ],
'processors' => [PsrLogMessageProcessor::class],
], ],
'syslog' => [ 'syslog' => [
'driver' => 'syslog', 'driver' => 'syslog',
'level' => env('LOG_LEVEL', 'debug'), 'level' => env('LOG_LEVEL', 'debug'),
'facility' => LOG_USER,
'replace_placeholders' => true,
], ],
'errorlog' => [ 'errorlog' => [
'driver' => 'errorlog', 'driver' => 'errorlog',
'level' => env('LOG_LEVEL', 'debug'), 'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
], ],
'null' => [ 'null' => [
@ -117,8 +126,10 @@ return [
'emergency' => [ 'emergency' => [
'path' => storage_path('logs/laravel.log'), 'path' => storage_path('logs/laravel.log'),
], ],
'flare' => [
'driver' => 'flare',
],
], ],
'slack' => env('LOG_SLACK_WEBHOOK_URL'),
]; ];

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