Configurado el logger
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Services\Auth0Service;
|
|||||||
use App\Services\PaginatorService;
|
use App\Services\PaginatorService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
|
|||||||
25
backend/app/Http/Middleware/LogEndpointHitMiddleware.php
Normal file
25
backend/app/Http/Middleware/LogEndpointHitMiddleware.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class LogEndpointHitMiddleware {
|
||||||
|
public function handle($request, Closure $next) {
|
||||||
|
$userId = $request->user ? $request->user->id : null;
|
||||||
|
$method = $request->getMethod();
|
||||||
|
$path = $request->getPathInfo();
|
||||||
|
|
||||||
|
Log::debug('User ' . $userId . ' hitting ' . $method . ' ' . $path . ' endpoint', [
|
||||||
|
'user' => $userId,
|
||||||
|
'method' => $method,
|
||||||
|
'path' => $path,
|
||||||
|
'input' => array_filter($request->input(), function ($key) {
|
||||||
|
return $key !== 'user';
|
||||||
|
}, ARRAY_FILTER_USE_KEY)
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,6 +60,7 @@ $app->singleton(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$app->configure('app');
|
$app->configure('app');
|
||||||
|
$app->configure('logging');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -72,12 +73,10 @@ $app->configure('app');
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// $app->middleware([
|
|
||||||
// App\Http\Middleware\ExampleMiddleware::class
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
$app->routeMiddleware([
|
$app->routeMiddleware([
|
||||||
'auth' => App\Http\Middleware\Auth0Middleware::class,
|
'auth' => App\Http\Middleware\Auth0Middleware::class,
|
||||||
|
'log_endpoint' => App\Http\Middleware\LogEndpointHitMiddleware::class
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
51
backend/config/logging.php
Normal file
51
backend/config/logging.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?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'),
|
||||||
|
|
||||||
|
'channels' => [
|
||||||
|
'stack' => [
|
||||||
|
'driver' => 'stack',
|
||||||
|
'channels' => ['daily', 'stderr'],
|
||||||
|
],
|
||||||
|
|
||||||
|
'daily' => [
|
||||||
|
'driver' => 'daily',
|
||||||
|
'path' => storage_path('logs/lumen_log.html'),
|
||||||
|
'formatter' => Monolog\Formatter\HtmlFormatter::class,
|
||||||
|
'level' => 'debug',
|
||||||
|
'days' => 14,
|
||||||
|
],
|
||||||
|
|
||||||
|
'stderr' => [
|
||||||
|
'driver' => 'monolog',
|
||||||
|
'handler' => StreamHandler::class,
|
||||||
|
'formatter' => Monolog\Formatter\LineFormatter::class,
|
||||||
|
'level' => 'debug',
|
||||||
|
'with' => [
|
||||||
|
'stream' => 'php://stderr',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'null' => [
|
||||||
|
'driver' => 'monolog',
|
||||||
|
'handler' => NullHandler::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
@@ -8,7 +8,7 @@ $router->get('/', function () use ($router) {
|
|||||||
return 'Public View';
|
return 'Public View';
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->group(['prefix' => 'api/v1', 'middleware' => 'auth'], function () use ($router) {
|
$router->group(['prefix' => 'api/v1', 'middleware' => ['auth', 'log_endpoint']], function () use ($router) {
|
||||||
$router->group(['prefix' => '/users'], function () use ($router) {
|
$router->group(['prefix' => '/users'], function () use ($router) {
|
||||||
$router->get('/', ['as' => 'users.all', 'uses' => 'UsuariosController@all']);
|
$router->get('/', ['as' => 'users.all', 'uses' => 'UsuariosController@all']);
|
||||||
$router->get('/{id}', ['as' => 'users.get', 'uses' => 'UsuariosController@get']);
|
$router->get('/{id}', ['as' => 'users.get', 'uses' => 'UsuariosController@get']);
|
||||||
|
|||||||
Reference in New Issue
Block a user