Skip to content

Commit

Permalink
small refactor + version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
arukompas committed Nov 18, 2022
1 parent 4f49a0b commit 436d997
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ Gate::define('deleteLogFolder', function (?User $user, LogFolder $folder) {

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

### Disabling Log Viewer

To disable web access to the Log Viewer, just add an environment variable to your `.env` file:

```env
LOG_VIEWER_ENABLED=false
```

## Troubleshooting

Here are some common problems and solutions.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opcodesio/log-viewer",
"version": "v1.7.0",
"version": "v1.7.1",
"description": "Fast and easy-to-use log viewer for your Laravel application",
"keywords": [
"arukompas",
Expand Down
16 changes: 9 additions & 7 deletions config/log-viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

return [

/*
|--------------------------------------------------------------------------
| Log Viewer
|--------------------------------------------------------------------------
| Log Viewer can be disabled, so it's no longer accessible via browser.
|
*/
'enabled' => env('LOG_VIEWER_ENABLED', true),

/*
|--------------------------------------------------------------------------
| Log Viewer Domain
Expand All @@ -25,13 +34,6 @@

'route_path' => 'log-viewer',

/*
|--------------------------------------------------------------------------
| Log Viewer Activation
|--------------------------------------------------------------------------
*/
'enabled' => true,

/*
|--------------------------------------------------------------------------
| Back to system URL
Expand Down
35 changes: 15 additions & 20 deletions src/LogViewerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@ public function register()
$this->app->singleton(PreferenceStore::class, PreferenceStore::class);
}

private function basePath(string $path): string
{
return __DIR__ . '/..' . $path;
}

/**
* Check if config is enabled
*
* @return bool
*/
public function isEnabled(): bool
{
return (bool) $this->app['config']->get("{$this->name}.enabled", true);
}

public function boot()
{
if ($this->app->runningInConsole()) {
Expand All @@ -51,7 +36,7 @@ public function boot()
$this->commands([GenerateDummyLogsCommand::class]);
}

if (!$this->isEnabled()) {
if (! $this->isEnabled()) {
return;
}

Expand All @@ -68,20 +53,30 @@ public function boot()
LogViewer::clearFileCache();
});

if (!Gate::has('downloadLogFile')) {
if (! Gate::has('downloadLogFile')) {
Gate::define('downloadLogFile', fn (mixed $user, LogFile $file) => true);
}

if (!Gate::has('downloadLogFolder')) {
if (! Gate::has('downloadLogFolder')) {
Gate::define('downloadLogFolder', fn (mixed $user, LogFolder $folder) => true);
}

if (!Gate::has('deleteLogFile')) {
if (! Gate::has('deleteLogFile')) {
Gate::define('deleteLogFile', fn (mixed $user, LogFile $file) => true);
}

if (!Gate::has('deleteLogFolder')) {
if (! Gate::has('deleteLogFolder')) {
Gate::define('deleteLogFolder', fn (mixed $user, LogFolder $folder) => true);
}
}

private function basePath(string $path): string
{
return __DIR__ . '/..' . $path;
}

private function isEnabled(): bool
{
return (bool) $this->app['config']->get("{$this->name}.enabled", true);
}
}

0 comments on commit 436d997

Please sign in to comment.