pkeidel/laralog

Logs a lot of informations like events, database queries, cache access, memory usage and a lot more

0.5.2 2022-02-07 19:46 UTC

This package is auto-updated.

Last update: 2024-04-08 00:36:36 UTC


README

Latest Version on Packagist Total Downloads

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

01_requests_per_route

License

The MIT License (MIT)