margatampu / laravel-inspector
Watching and observing requests, logs, and listed models to maintain all possible acivities.
Requires
- php: ^7.0
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- ext-curl: *
README
Watching and observing requests, logs, and listed models to maintain all possible activities. Laravel inspector use to do it and storing data in separate database.
Installation
Require this package with composer.
$ composer require margatampu/laravel-inspector
Integration
Package tested and worked with Laravel and Lumen framework (5.7+).
Laravel: After installation using composer finishes up, you'll have to add the following line to your config/app.php
:
MargaTampu\LaravelInspector\InspectorServiceProvider::class
Lumen: For Lumen, you'll have to add the following line to your bootstrap/app.php
:
$app->register(MargaTampu\LaravelInspector\InspectorServiceProvider::class);
Laravel: Then copy inspector
config file from laravel-inspector to your config folder:
$ php artisan vendor:publish --provider="MargaTampu\LaravelInspector\InspectorServiceProvider"
Lumen: For Lumen, you need to copy file manually to your config folder and enable it in bootstrap/app.php
:
$app->configure('inspector');
After configuration, migrate all necessary database structure from laravel-inspector with (prerequisite setting database in .env
file):
$ php artisan migrate
To make sure laravel-inspector running securily, you need to generate inspector auth token using console command line with default value:
$ php artisan inspector:auth
It will generate a random key, and you need to store it in your .env file.
Last step for your integration, you need to add this line to your routes\api.php
file to use laravel-inspector api route to handle storing data to database.
MargaTampu\LaravelInspector\Inspector::api();
Configuring config file
For your models activity, you need to listing all your models you want to watched. Placed all your models in config\inspector.php
file inside models
element.
'models' => [ 'App\User' ],
Setup env file
After installation and some integration, you need to update setup in your .env
file. Besides database setting, you can add variable:
INSPECTOR_QUEUE_NAME
, separate or merge inspector queue with your laravel default queue.INSPECTOR_LOG
, to limit log level watched.INSPECTOR_MODEL_ENABLE
, set to true to enable watched listed models.INSPECTOR_LOG_ENABLE
, set to true to enable watched all log generated.INSPECTOR_REQUEST_ENABLE
, set to true to enable watched request called.INSPECTOR_AUTHORIZATION
, to store your generated auth token.
Don't forgot to change your APP_URL
as well with your current application domain url. It is use as api route url to store all your inspector data.
Go Ahaed
For expert use, you can ignore last step for integration steps for copying inspector API, and copied laravel-inspector api routes manually to your routes/api.php
file and use your own controller to maintain data before store to database.
Then, you can store your destination url in .env file
using this variables:
INSPECTOR_MODEL_ENDPOINT
, full url to handle model inspector.INSPECTOR_LOG_ENDPOINT
, full url to handle log inspector.INSPECTOR_REQUEST_ENDPOINT
, full url to handle request inspector.
Migration Customization
If you plan to separate service and consumer, you can ignore migrations of inspector package to prevent project migrate unnecessary tables to your consumer database. You should call the Inspector::ignoreMigrations
method in the register method of your AppServiceProvider
.
Queueing Jobs
To prevent inspector slowing your projects, you can queueing inspector jobs using separate queue name inspector
. You can run single queue worker for it using this command:
$ php artisan queue:work --tries=1 --queue=inspector
Usage
To use this package, after all integration steps done. You will have your requests, logs and models activity in database.
Console Command
You did run inspector:auth command before to generate new inspector default auth token. Beside it, we have several commands available:
- Custom inspector auth name
You can custom your own inspector auth name using this command:
$ php artisan inspector:auth --new
- Update name of existing inspector auth
You allowed to rename your existing inpector auth name using: Note: Replace {$id} with your inspector auth id
$ php artisan inspector:auth --name={$id}
- Refresh token of existing inspector auth
Like inspector auth name, you also allowed to change token or refresh it using: Note: Replace {$id} with your inspector auth id
$ php artisan inspector:auth --refresh={$id}
Testing
For some laravel/lumen project, this package still not stable in some parts. If you want to test this package, you have several command to test it.
- Run all modules test with a single command
You can run a single command to run test all modules (model, log, and request).
$ php artisan inspector:test --all
- Run model module test only
Since you can enable and disable module in configuration file, you also enable to run single module too.
$ php artisan inspector:test --model $ php artisan inspector:test --log $ php artisan inspector:test --request
Prerequisit for testing modules
To ensure your package test module run smoothly, you need to recheck some configurations:
- Since the package test using running database (not separated test database), please change your current database to new fresh database or you will need to delete inserted data manually.
- Queue connection using sync. Use connection besides it will force test to exit.
- Check if module enable for model, log, and/or request. Disable module will not run test for it.
- For model module test, package use User class model, so you need to ensure that User model and factory are available for use. But if you disable model module, you can skip this step.
- For request module test, package use guzzle/http to acces your main page (url('/')), please ensure that url exist to access. But if you disable request module, you can skipt this step too.
License
This laravel-teams-logging package is available under the MIT license. See the LICENSE file for more info.