Authorizing access to individual log files

If you have published the configuration file, make sure the middleware and api_middleware options include the AuthorizeLogViewer middleware.

Log Viewer provides easy ways to download and delete log files right from the user interface. These actions are great for managing your logs and keeping everything tidy.

You can limit these abilities based on the log file and the user authenticated, by using Laravel Gates.

This is very useful when you don't want particular developers/admins to download or delete certain log files. You can even protect all log files from being deleted.

Authorizing downloads

To control who can download which individual log files, 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.    });}

Log Viewer allows downloading whole groups of log files as well.

To control who can download which log groups, define a downloadLogFolder authorization gate in your App\Providers\AuthServiceProvider class:

use Opcodes\LogViewer\LogFolder;//...Gate::define('downloadLogFolder', function (?User $user, LogFolder $folder) {    // return true if the user is allowed to download the whole folder.});

Individual file permissions are also checked before downloading them, to avoid accidental downloads of protected log files.

Authorizing log file deletion

To control who can delete which individual log files, 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.    });}

Log Viewer allows deleting whole groups of log files as well.

To control who can delete which log groups, define a deleteLogFolder authorization gate in your App\Providers\AuthServiceProvider class:

use Opcodes\LogViewer\LogFolder;//...Gate::define('deleteLogFolder', function (?User $user, LogFolder $folder) {    // return true if the user is allowed to delete the whole folder.});

Individual file permissions are also checked before deleting them, to avoid accidental deletion of protected log files.

Support

If you have any questions, feedback, or need any help setting up Log Viewer within your project, feel free to reach out via GitHub Discussions or GitHub Issues .