loggitack / loggitrack-sdk-laravel
LoggiTrack integration SDK for Laravel
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/loggitack/loggitrack-sdk-laravel
Requires
- php: ^7.4|^8.2
- guzzlehttp/guzzle: ^7.2
Requires (Dev)
- phpunit/phpunit: ^9.0
README
The Loggitrack Laravel SDK provides seamless integration of the Loggitrack API into your Laravel application, allowing you to track API requests and responses, analyze performance metrics, and monitor user behavior.
Installation
Prerequisites
- PHP ^8.2
- Laravel ^8.0|^9.0|^10.0
Installation Steps
-
Require the SDK via Composer:
composer require loggitack/loggitrack-sdk-laravel
-
Publish the configuration file:
php artisan vendor:publish --provider="Loggitrack\Laravel\Providers\LoggitrackServiceProvider" -
Configure the SDK: Open the published configuration file
config/loggitrack.phpand update the settings as needed:<?php return [ 'api_key' => env('LOGGITRACK_API_KEY', ''), 'api_url' => env('LOGGITRACK_API_URL', ''), 'observed_models' => [ // Example: App\Models\User::class, ], // Additional configuration options 'queueable' => false, /** * the request logger and model logger will not save these fields. */ 'escaped_fields' => [ // 'password', 'api_key' ] ];
Set the
LOGGITRACK_API_KEYandLOGGITRACK_API_URLenvironment variables in your.envfile:LOGGITRACK_API_KEY=your-api-key LOGGITRACK_API_URL=http://127.0.0.1:3020
Usage
Middleware
The SDK includes a LogRequestMiddleware middleware that should be added to each route you want to observe. This middleware will log the requests and responses for the specified endpoints.
-
Register the Middleware: Open the
app/Http/Kernel.phpfile and add the middleware to the route middleware array:protected $routeMiddleware = [ // Other middleware 'loggitrack' => \Loggitrack\Laravel\Http\Middleware\LogRequestMiddleware::class, ];
-
Apply the Middleware to Routes: Apply the
loggitrackmiddleware to the routes you want to observe. For example:Route::middleware(['loggitrack'])->group(function () { Route::get('/users', 'UserController@index'); Route::post('/users', 'UserController@store'); // Add other routes as needed });
Example Usage
-
Set Up Observed Models: Add the models you want to observe to the
observed_modelsarray in the configuration file:'observed_models' => [ App\Models\User::class, App\Models\Order::class, ],
-
Send API Requests: The SDK will automatically log the requests and responses for the observed endpoints. You can use your application as usual, and the logs will be sent to the Loggitrack API for analysis.
Additional Configuration Options
The SDK provides additional configuration options that can be customized in the config/loggitrack.php file:
- queueable: Set to
trueto queue the logging requests for asynchronous processing. Defaults tofalse.
Troubleshooting
If you encounter any issues during the installation or usage of the Loggitrack Laravel SDK, refer to the following steps:
- Ensure all prerequisites are met.
- Verify your configuration settings in
config/loggitrack.php. - Check the Laravel logs for any errors related to the SDK.
Contributing
Contributions are welcome! Please submit a pull request or open an issue to contribute.
License
The MIT License (MIT). Please see License File for more information.