У приложения на Laravel посмотреть логи http-запросов
Досталось легаси приложение без документации, но есть полный доступ к "продакшен" версии.
Краткая сводка информации по нему.
/app # php artisan tinker
Psy Shell v0.11.12 (PHP 8.2.2 — cli) by Justin Hileman
> app()
= Illuminate\Foundation\Application {#2
configurationIsCached: false,
environment: "production",
environmentFile: ".env",
isLocal: false,
routesAreCached: false,
runningUnitTests: false,
version: "9.52.11",
path: "/app/app",
basePath: "/app",
configPath: "/app/config",
databasePath: "/app/database",
langPath: "/app/resources/lang",
publicPath: "/app/public",
storagePath: "/app/storage",
bootstrapPath: "/app/bootstrap",
}
Как я понимаю тут определены какие-то правила логирования.
cat config/logging.php
<?php
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/
'default' => env('LOG_CHANNEL', 'stack'),
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "monolog",
| "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'sentry'],
'ignore_exceptions' => false,
],
'event_log' => [
'driver' => 'sentry',
'name' => 'Events',
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => env('LOG_LEVEL', 'critical'),
],
'papertrail' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
],
'stderr' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],
'syslog' => [
'driver' => 'syslog',
'level' => env('LOG_LEVEL', 'debug'),
],
'errorlog' => [
'driver' => 'errorlog',
'level' => env('LOG_LEVEL', 'debug'),
],
'null' => [
'driver' => 'monolog',
'handler' => NullHandler::class,
],
'emergency' => [
'path' => storage_path('logs/laravel.log'),
],
'sentry' => [
'driver' => 'sentry',
],
],
];
Нужно посмотреть логи http-запросов, но все что я могу получить на текущий момент выглядит так.
php artisan log:show
2025-02-20 09:53:49 production.ERROR @daily:
There are no commands defined in the "get:" namespace.
exception: [object] (Symfony\Component\Console\Exception\NamespaceNotFoundException(code: 0): There are no commands defined in the "get:" namespace. at /app/vendor/symfony/console/Application.php:657)
[stacktrace]
#0 /app/vendor/symfony/console/Application.php(708): Symfony\Component\Console\Application->findNamespace('get:')
#1 /app/vendor/symfony/console/Application.php(262): Symfony\Component\Console\Application->find('get::token')
[...]
Это я знакомился с php artisan
и вводил разные команды.
У меня есть доступ к логам docker где находится данное приложение, но они мало информативны.
docker-compose logs -f --tail=0 server
Attaching to server
server | - - 20/Feb/2025:11:53:07 +0000 "POST /index.php" 404
Само тело ответа
{
"error":
{
"originalResponseStatusCode": 404,
"description": "ExternalServiceError",
"type": "ExternalServiceError"
}
}
Хочется понимать, что происходит на сервере когда он получает запрос и видеть стектрейс при ошибке.