pkeidel / laralog
记录大量信息,如事件、数据库查询、缓存访问、内存使用等
0.5.2
2022-02-07 19:46 UTC
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
此包受laravel-debugbar和clockwork的启发,但将数据记录到Elasticsearch服务器。它注册了一个中间件,默认情况下在terminate()中向Elasticsearch发送HTTP请求,以防止拖慢您的页面。
它记录:响应数据(如响应时间和HTTP状态码)、数据库查询、最频繁触发的事件、自定义数据。
安装
您可以通过composer安装此包
composer require pkeidel/laralog
将中间件添加到您的./app/Http/Kernel.php中
\PKeidel\Laralog\Middleware\Logging::class,
配置
将这些值添加到您的.env文件中
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
或获取config/laralog.php文件并在其中修改。例如
artisan vendor:publish --tag=config --provider="PKeidel\Laralog\LaralogServiceProvider"
可选:直接发送请求(不在terminate()中)
config/laralog.php: 'sendlater' => false,
记录异常
只需将以下内容添加到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', ]);
输出
Elasticsearch
创建索引模板
artisan vendor:publish --tag=es-template --provider="PKeidel\Laralog\LaralogServiceProvider"
artisan laralog:es:install
示例Kibana可视化
按路由的请求数量
许可证
MIT许可证(MIT)
