Git Product home page Git Product logo

Comments (4)

hedii avatar hedii commented on May 30, 2024 1

Log::channel('gelf')->withContext([...

from laravel-gelf-logger.

hedii avatar hedii commented on May 30, 2024

Hi, please share your configuration and code that shows something that is not working

from laravel-gelf-logger.

iamwildtuna avatar iamwildtuna commented on May 30, 2024

Configuration:
image

Middleware:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

class AssignRequestId
{
    /**
     * Обработчик входящего запроса
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $requestId = (string) Str::uuid();

        Log::withContext([
            'request-id' => $requestId
        ]);
        
        $request->headers->set('Request-Id', $requestId);
        return $next($request)->header('Request-Id', $requestId);
    }
}

Used code:

<?php

namespace App\Http\Controllers;

use App\Http\ApiResponseInjectController;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;

class TokenController extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests, ApiResponseInjectController;

    /**
     * Создание JWT 
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function generate(Request $request)
    {
        $payload = [
            'iss' => 'localhost',
            'aud' => 'localhost',
            'iat' => time(),
            'nbf' => time(),
            'exp' => time() + 64000,
            'user_id' => rand(100000, 999999),
            'user_name' => 'test',
            'rights' => []
        ];
        
        $jwt = JWT::encode($payload, config('app.jwt_private'), 'RS256');
        Log::channel('gelf')->debug('Выпущен токен JWT', ['jwt' => $jwt]);
        return $this->apiResponse->getSuccess(['token' => $jwt]);
    }
}

Result in ELK:
image

from laravel-gelf-logger.

iamwildtuna avatar iamwildtuna commented on May 30, 2024

Thanks! It really works, the IDE just highlights that there is no method and did not try.

image

image

from laravel-gelf-logger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.