07
SepLog Viewer helps you quickly and clearly see individual log entries, to search, filter, and make sense of your Laravel logs fast. It is free and easy to install.
To install this package via composer, Run:
composer require opcodesio/log-viewer
Once the installation is complete, you will be able to access Log Viewer directly in your browser.
By default, the application is available at: {APP_URL}/log-viewer
.
(for example: https://my-app.test/log-viewer
)
Several things can be configured to have different access based on the user logged in, or the log file in action.
Here are the permissions and how to set them up.
Authorizing Log Viewer access
You can limit who has access to the Log Viewer in several ways.
Via “auth” callback
You can limit access to the Log Viewer by providing a custom authorization callback to the LogViewer::auth()
method within your AppServiceProvider
, like so:
use Opcodes\LogViewer\Facades\LogViewer;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
LogViewer::auth(function ($request) {
// return true to allow viewing the Log Viewer.
});
// Here's an example:
LogViewer::auth(function ($request) {
return $request->user()
&& in_array($request->user()->email, [
// 'john@example.com',
]);
});
}
Via “viewLogViewer” gate
Another easy way to limit access to the Log Viewer is via Laravel Gates. Just define a viewLogViewer authorization gate in your App\Providers\AuthServiceProvider
class:
use App\Models\User;
use Illuminate\Support\Facades\Gate;
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Gate::define('viewLogViewer', function (?User $user) {
// return true if the user is allowed access to the Log Viewer
});
}
You can limit the ability to download log files via Laravel Gates. Just define a downloadLogFile
authorization gate in your App\Providers\AuthServiceProvider
class:
use App\Models\User;
use Opcodes\LogViewer\LogFile;
use Illuminate\Support\Facades\Gate;
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Gate::define('downloadLogFile', function (?User $user, LogFile $file) {
// return true if the user is allowed to download the specific log file.
});
}
You can limit the ability to delete log files via Laravel Gates. Just define a deleteLogFile
authorization gate in your App\Providers\AuthServiceProvider
class:
use App\Models\User;
use Opcodes\LogViewer\LogFile;
use Illuminate\Support\Facades\Gate;
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Gate::define('deleteLogFile', function (?User $user, LogFile $file) {
// return true if the user is allowed to delete the specific log file.
});
}
For more details, Visit Github.
If you have a stunning idea then Codebrisk is always here to convert your ideas into reality. Our team of expert developers is trained in Laravel custom web app development, CRM software development, and e-commerce app development. We run with a superior level of agility and a vast Laravel ecosystem to customize the software for your business. For more details, please contact us or you can launch a project with us.
Published at : 07-09-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project