pkeidel / laralog
Logs a lot of informations like events, database queries, cache access, memory usage and a lot more
Requires
- php: ^7.4 | ^8.0
- ext-json: *
- ext-sockets: *
- guzzlehttp/guzzle: ^6.5 || ^7.0
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: >=8.0
Suggests
- influxdata/influxdb-client-php: Needed if laralog.output.type is 'influxdb'
README
This package is inspired by laravel-debugbar and clockwork
but logs the data to an elasticsearch server. It registers a middleware and the HTTP request to elasticsearch is send within terminate()
by default to not slow down your page.
It logs: response data (like response time and http status code), database queries, most fired events, custom data.
Installation
You can install the package via composer:
composer require pkeidel/laralog
Add the middleware to your ./app/Http/Kernel.php:
\PKeidel\Laralog\Middleware\Logging::class,
Configuration
Add these values to your .env file:
LARALOG_ENABLED=true LARALOG_ES_HOST=https://es01.example.com LARALOG_ES_INDEX=myindex LARALOG_ES_USERNAME=abcdefghi LARALOG_ES_PASSWORD=!top5scr3t! LARALOG_ES_VERIFYSSL=true LARALOG_ES_PIPELINE=ipgeo
Or get the config/laralog.php file and modify it there. For example to
artisan vendor:publish --tag=config --provider="PKeidel\Laralog\LaralogServiceProvider"
Optional: Send request direct (not in terminate()
):
config/laralog.php: 'sendlater' => false,
Log exceptions
Simply add this to app/Exceptions/Handler::report(Exception $exception)
:
$pklaralog = resolve('pklaralog'); $pklaralog->get('errors')->push([ 'type' => 'error', 'time' => round(microtime(true), 3), 'exception' => get_class($exception), 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'route' => optional(request()->route())->uri() ?? 'unknown', ]);
Outputs
Elasticsearch
Create index template:
artisan vendor:publish --tag=es-template --provider="PKeidel\Laralog\LaralogServiceProvider"
artisan laralog:es:install
Example Kibana visualisations
Requests per route
License
The MIT License (MIT)