PHP code example of hewerthomn / laravel-error-tracker
1. Go to this page and download the library: Download hewerthomn/laravel-error-tracker library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hewerthomn / laravel-error-tracker example snippets
use Illuminate\Support\Facades\Gate;
Gate::define('viewErrorTracker', function ($user = null) {
return true;
});
use Hewerthomn\ErrorTracker\Actions\RecordThrowableAction;
use Illuminate\Foundation\Configuration\Exceptions;
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->dontReportDuplicates();
$exceptions->report(function (\Throwable $e) {
app(RecordThrowableAction::class)->handle($e);
});
})
'stacktrace' => [
'smart_grouping' => true,
'project_paths' => [
app_path(),
base_path('routes'),
base_path('database'),
base_path('config'),
base_path('packages'),
base_path('modules'),
],
'project_namespaces' => [
'App\\',
'Database\\',
],
'non_project_paths' => [
base_path('vendor'),
base_path('storage/framework'),
base_path('bootstrap/cache'),
],
'collapse_non_project_frames' => true,
'show_source_context' => true,
'source_context_lines' => 5,
'path_display' => env('ERROR_TRACKER_STACKTRACE_PATH_DISPLAY', 'relative'),
'store_absolute_paths' => env('ERROR_TRACKER_STACKTRACE_STORE_ABSOLUTE_PATHS', false),
'source_context' => [
'enabled' => env('ERROR_TRACKER_SOURCE_CONTEXT_ENABLED', true),
'lines_before' => 5,
'lines_after' => 5,
'max_frames' => 5,
'project_only' => true,
'fallback_to_throwing_frame' => true,
'max_file_size_kb' => 512,
'paths' => [
app_path(),
base_path('routes'),
base_path('database'),
base_path('config'),
base_path('packages'),
base_path('modules'),
],
'excluded_paths' => [
base_path('vendor'),
storage_path(),
base_path('bootstrap/cache'),
],
],
'store_arguments' => false,
],
'source_context' => [
'enabled' => env('ERROR_TRACKER_SOURCE_CONTEXT_ENABLED', true),
'lines_before' => 5,
'lines_after' => 5,
'max_frames' => 5,
'project_only' => true,
'fallback_to_throwing_frame' => true,
'max_file_size_kb' => 512,
'paths' => [
app_path(),
base_path('routes'),
base_path('database'),
base_path('config'),
base_path('packages'),
base_path('modules'),
],
'excluded_paths' => [
base_path('vendor'),
storage_path(),
base_path('bootstrap/cache'),
],
],
'auto_resolve' => [
'enabled' => env('ERROR_TRACKER_AUTO_RESOLVE_ENABLED', false),
'after_days' => env('ERROR_TRACKER_AUTO_RESOLVE_AFTER_DAYS', 14),
'statuses' => ['open'],
'levels' => ['warning', 'error'],
'environments' => null,
'reason' => 'Automatically resolved after :days days without new events.',
],
use Illuminate\Support\Facades\Schedule;
Schedule::command('error-tracker:auto-resolve')->daily();
'database' => [
'connection' => env('ERROR_TRACKER_DB_CONNECTION'),
],
use Hewerthomn\ErrorTracker\Actions\RecordThrowableAction;
use Hewerthomn\ErrorTracker\Support\ErrorPageState;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
//
})
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->dontReportDuplicates();
$exceptions->report(function (\Throwable $e) {
$result = app(RecordThrowableAction::class)->handle($e);
if ($result) {
app(ErrorPageState::class)->set($result);
}
});
$exceptions->render(function (\Throwable $e, Request $request) {
if (! config('error-tracker.error_page.enabled', true)) {
return null;
}
if (
config('error-tracker.error_page.only_when_debug_disabled', true) &&
config('app.debug')
) {
return null;
}
if (
config('error-tracker.error_page.only_html_requests', true) &&
$request->expectsJson()
) {
return null;
}
$status = method_exists($e, 'getStatusCode')
? (int) $e->getStatusCode()
: 500;
if ($status < 500) {
return null;
}
$result = app(ErrorPageState::class)->get();
$event = $result?->event;
$issue = $result?->issue;
$user = $request->user();
$showFeedbackForm =
config('error-tracker.feedback.enabled', false) &&
$event?->feedback_token &&
(
$user ||
config('error-tracker.feedback.allow_guest', true)
) &&
(
! config('error-tracker.feedback.only_production', false) ||
app()->environment('production')
);
$feedbackName = $user ? data_get($user, 'name') : null;
$feedbackEmail = $user ? data_get($user, 'email') : null;
$isFeedbackUserAuthenticated = (bool) $user;
$lockAuthenticatedUserFields = $isFeedbackUserAuthenticated;
return response()->view('error-tracker::error.exception', [
'title' => config('error-tracker.error_page.title', 'Something went wrong'),
'message' => config(
'error-tracker.error_page.message',
'An unexpected error occurred. Please try again in a moment.'
),
'showReference' => config('error-tracker.error_page.show_reference', true),
'reference' => $event?->uuid,
'event' => $event,
'issue' => $issue,
'showFeedbackForm' => $showFeedbackForm,
'collectName' => config('error-tracker.feedback.collect_name', true),
'collectEmail' => config('error-tracker.feedback.collect_email', true),
'authenticatedUser' => $user,
'feedbackUser' => $user,
'feedbackName' => $feedbackName,
'feedbackEmail' => $feedbackEmail,
'isFeedbackUserAuthenticated' => $isFeedbackUserAuthenticated,
'lockAuthenticatedUserFields' => $lockAuthenticatedUserFields,
'pageUrl' => $request->fullUrl(),
], $status);
});
})
->create();
env
ERROR_TRACKER_GITHUB_ENABLED=false
ERROR_TRACKER_GITHUB_TOKEN=
ERROR_TRACKER_GITHUB_REPOSITORY=owner/repository
ERROR_TRACKER_GITHUB_LABELS=bug,error-tracker
bash
composer error-tracker:install
php artisan migrate
php artisan error-tracker:doctor
bash
php artisan error-tracker:install --with-demo
bash
php artisan error-tracker:install --guided
bash
php artisan error-tracker:install --preset=local
php artisan error-tracker:install --preset=production
php artisan error-tracker:install --preset=minimal
php artisan error-tracker:install --preset=demo
bash
composer update hewerthomn/laravel-error-tracker -W
php artisan vendor:publish --tag=error-tracker-migrations
php artisan migrate
php artisan optimize:clear
php artisan error-tracker:doctor
text
Error Tracker - {APP_NAME}
text
config/error-tracker.php
text
/error-tracker?q=checkout%20status:open%20level:error&period=24h&sort=last_seen_at&direction=desc
bash
php artisan error-tracker:demo --purge
bash
composer analyse