[7.x] Add log viewer (#1972)a

* add opcodesio/log-viewer

* set up with custom permission

---------

Co-authored-by: Nabeel S. <nabeelio@users.noreply.github.com>
This commit is contained in:
Arthur Parienté 2025-02-01 03:56:50 +01:00 committed by GitHub
parent bcca922344
commit 22c548c7ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 436 additions and 3 deletions

View File

@ -57,3 +57,6 @@
- name: modules
display_name: Modules
description: Add/Edit Modules
- name: logs
display_name: Logs
description: View logs

View File

@ -2,7 +2,10 @@
namespace App\Providers;
use App\Models\User;
use Illuminate\Auth\Access\Response;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
@ -22,6 +25,10 @@ class AuthServiceProvider extends ServiceProvider
*/
public function boot()
{
//
Gate::define('viewLogViewer', function (?User $user): Response {
return $user?->ability('admin', 'logs')
? Response::allow()
: Response::deny('You do not have permission to access this page.');
});
}
}

View File

@ -91,7 +91,8 @@
"spatie/laravel-activitylog": "^4.7",
"socialiteproviders/vatsim": "^5.0",
"socialiteproviders/ivao": "^4.0",
"mailersend/laravel-driver": "^2.6"
"mailersend/laravel-driver": "^2.6",
"opcodesio/log-viewer": "^3.14"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.8.1",

143
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2ff9b6c21883cbd4c0e36755dca7e570",
"content-hash": "2f6f849739b1ee9fb0fe141dc285b5e8",
"packages": [
{
"name": "akaunting/laravel-money",
@ -6508,6 +6508,147 @@
},
"time": "2021-12-15T12:32:42+00:00"
},
{
"name": "opcodesio/log-viewer",
"version": "v3.14.0",
"source": {
"type": "git",
"url": "https://github.com/opcodesio/log-viewer.git",
"reference": "876166da7af4864faca7100e63534116c1c295b9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/opcodesio/log-viewer/zipball/876166da7af4864faca7100e63534116c1c295b9",
"reference": "876166da7af4864faca7100e63534116c1c295b9",
"shasum": ""
},
"require": {
"illuminate/contracts": "^8.0|^9.0|^10.0|^11.0",
"opcodesio/mail-parser": "^0.1.6",
"php": "^8.0"
},
"conflict": {
"arcanedev/log-viewer": "^8.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.2",
"itsgoingd/clockwork": "^5.1",
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.0|^8.0",
"orchestra/testbench": "^7.6|^8.0|^9.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"spatie/test-time": "^1.3"
},
"suggest": {
"guzzlehttp/guzzle": "Required for multi-host support. ^7.2"
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"LogViewer": "Opcodes\\LogViewer\\Facades\\LogViewer"
},
"providers": [
"Opcodes\\LogViewer\\LogViewerServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Opcodes\\LogViewer\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Arunas Skirius",
"email": "arukomp@gmail.com",
"role": "Developer"
}
],
"description": "Fast and easy-to-use log viewer for your Laravel application",
"homepage": "https://github.com/opcodesio/log-viewer",
"keywords": [
"arukompas",
"better-log-viewer",
"laravel",
"log viewer",
"logs",
"opcodesio"
],
"support": {
"issues": "https://github.com/opcodesio/log-viewer/issues",
"source": "https://github.com/opcodesio/log-viewer/tree/v3.14.0"
},
"funding": [
{
"url": "https://www.buymeacoffee.com/arunas",
"type": "custom"
},
{
"url": "https://github.com/arukompas",
"type": "github"
}
],
"time": "2025-01-10T12:03:56+00:00"
},
{
"name": "opcodesio/mail-parser",
"version": "v0.1.6",
"source": {
"type": "git",
"url": "https://github.com/opcodesio/mail-parser.git",
"reference": "639ef31cbd146a63416283e75afce152e13233ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/opcodesio/mail-parser/zipball/639ef31cbd146a63416283e75afce152e13233ea",
"reference": "639ef31cbd146a63416283e75afce152e13233ea",
"shasum": ""
},
"require": {
"php": "^8.0"
},
"require-dev": {
"pestphp/pest": "^2.16",
"symfony/var-dumper": "^6.3"
},
"type": "library",
"autoload": {
"psr-4": {
"Opcodes\\MailParser\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Arunas Skirius",
"email": "arukomp@gmail.com",
"role": "Developer"
}
],
"description": "Parse emails without the mailparse extension",
"keywords": [
"arukompas",
"email",
"email parser",
"mail",
"opcodesio",
"php"
],
"support": {
"issues": "https://github.com/opcodesio/mail-parser/issues",
"source": "https://github.com/opcodesio/mail-parser/tree/v0.1.6"
},
"time": "2023-11-19T08:47:43+00:00"
},
{
"name": "paragonie/constant_time_encoding",
"version": "v2.6.3",

234
config/log-viewer.php Normal file
View File

@ -0,0 +1,234 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Log Viewer
|--------------------------------------------------------------------------
| Log Viewer can be disabled, so it's no longer accessible via browser.
|
*/
'enabled' => env('LOG_VIEWER_ENABLED', true),
'api_only' => env('LOG_VIEWER_API_ONLY', false),
'require_auth_in_production' => true,
/*
|--------------------------------------------------------------------------
| Log Viewer Domain
|--------------------------------------------------------------------------
| You may change the domain where Log Viewer should be active.
| If the domain is empty, all domains will be valid.
|
*/
'route_domain' => null,
/*
|--------------------------------------------------------------------------
| Log Viewer Route
|--------------------------------------------------------------------------
| Log Viewer will be available under this URL.
|
*/
'route_path' => '/admin/log-viewer',
/*
|--------------------------------------------------------------------------
| Back to system URL
|--------------------------------------------------------------------------
| When set, displays a link to easily get back to this URL.
| Set to `null` to hide this link.
|
| Optional label to display for the above URL.
|
*/
'back_to_system_url' => '/admin',
'back_to_system_label' => null, // Displayed by default: "Back to {{ app.name }}"
/*
|--------------------------------------------------------------------------
| Log Viewer time zone.
|--------------------------------------------------------------------------
| The time zone in which to display the times in the UI. Defaults to
| the application's timezone defined in config/app.php.
|
*/
'timezone' => null,
/*
|--------------------------------------------------------------------------
| Log Viewer route middleware.
|--------------------------------------------------------------------------
| Optional middleware to use when loading the initial Log Viewer page.
|
*/
'middleware' => [
'web',
\Opcodes\LogViewer\Http\Middleware\AuthorizeLogViewer::class,
],
/*
|--------------------------------------------------------------------------
| Log Viewer API middleware.
|--------------------------------------------------------------------------
| Optional middleware to use on every API request. The same API is also
| used from within the Log Viewer user interface.
|
*/
'api_middleware' => [
\Opcodes\LogViewer\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Opcodes\LogViewer\Http\Middleware\AuthorizeLogViewer::class,
],
'api_stateful_domains' => env('LOG_VIEWER_API_STATEFUL_DOMAINS') ? explode(',', env('LOG_VIEWER_API_STATEFUL_DOMAINS')) : null,
/*
|--------------------------------------------------------------------------
| Log Viewer Remote hosts.
|--------------------------------------------------------------------------
| Log Viewer supports viewing Laravel logs from remote hosts. They must
| be running Log Viewer as well. Below you can define the hosts you
| would like to show in this Log Viewer instance.
|
*/
'hosts' => [
'local' => [
'name' => ucfirst(env('APP_ENV', 'local')),
],
// 'staging' => [
// 'name' => 'Staging',
// 'host' => 'https://staging.example.com/log-viewer',
// 'auth' => [ // Example of HTTP Basic auth
// 'username' => 'username',
// 'password' => 'password',
// ],
// 'verify_server_certificate' => true,
// ],
//
// 'production' => [
// 'name' => 'Production',
// 'host' => 'https://example.com/log-viewer',
// 'auth' => [ // Example of Bearer token auth
// 'token' => env('LOG_VIEWER_PRODUCTION_TOKEN'),
// ],
// 'headers' => [
// 'X-Foo' => 'Bar',
// ],
// 'verify_server_certificate' => true,
// ],
],
/*
|--------------------------------------------------------------------------
| Include file patterns
|--------------------------------------------------------------------------
|
*/
'include_files' => [
'*.log',
'**/*.log',
// You can include paths to other log types as well, such as apache, nginx, and more.
// This key => value pair can be used to rename and group multiple paths into one folder in the UI.
'/var/log/httpd/*' => 'Apache',
'/var/log/nginx/*' => 'Nginx',
// MacOS Apple Silicon logs
'/opt/homebrew/var/log/nginx/*',
'/opt/homebrew/var/log/httpd/*',
'/opt/homebrew/var/log/php-fpm.log',
'/opt/homebrew/var/log/postgres*log',
'/opt/homebrew/var/log/redis*log',
'/opt/homebrew/var/log/supervisor*log',
// '/absolute/paths/supported',
],
/*
|--------------------------------------------------------------------------
| Exclude file patterns.
|--------------------------------------------------------------------------
| This will take precedence over included files.
|
*/
'exclude_files' => [
// 'my_secret.log'
],
/*
|--------------------------------------------------------------------------
| Hide unknown files.
|--------------------------------------------------------------------------
| The include/exclude options above might catch files which are not
| logs supported by Log Viewer. In that case, you can hide them
| from the UI and API calls by setting this to true.
|
*/
'hide_unknown_files' => true,
/*
|--------------------------------------------------------------------------
| Shorter stack trace filters.
|--------------------------------------------------------------------------
| Lines containing any of these strings will be excluded from the full log.
| This setting is only active when the function is enabled via the user interface.
|
*/
'shorter_stack_trace_excludes' => [
'/vendor/symfony/',
'/vendor/laravel/framework/',
'/vendor/barryvdh/laravel-debugbar/',
],
/*
|--------------------------------------------------------------------------
| Cache driver
|--------------------------------------------------------------------------
| Cache driver to use for storing the log indices. Indices are used to speed up
| log navigation. Defaults to your application's default cache driver.
|
*/
'cache_driver' => env('LOG_VIEWER_CACHE_DRIVER', null),
/*
|--------------------------------------------------------------------------
| Cache key prefix
|--------------------------------------------------------------------------
| Log Viewer prefixes all the cache keys created with this value. If for
| some reason you would like to change this prefix, you can do so here.
| The format of Log Viewer cache keys is:
| {prefix}:{version}:{rest-of-the-key}
|
*/
'cache_key_prefix' => 'lv',
/*
|--------------------------------------------------------------------------
| Chunk size when scanning log files lazily
|--------------------------------------------------------------------------
| The size in MB of files to scan before updating the progress bar when searching across all files.
|
*/
'lazy_scan_chunk_size_in_mb' => 50,
'strip_extracted_context' => true,
];

1
public/vendor/log-viewer/app.css vendored Normal file

File diff suppressed because one or more lines are too long

2
public/vendor/log-viewer/app.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,33 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <http://feross.org>
* @license MIT
*/
/*!
* pinia v2.2.2
* (c) 2024 Eduardo San Martin Morote
* @license MIT
*/
/*! #__NO_SIDE_EFFECTS__ */
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/**
* @vue/shared v3.4.38
* (c) 2018-present Yuxi (Evan) You and Vue contributors
* @license MIT
**/

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

View File

@ -0,0 +1,7 @@
{
"/app.js": "/app.js?id=6c51578cafcbf2f5e90fbf568a61ab8f",
"/app.css": "/app.css?id=5593a0331dd40729ff41e32a6035d872",
"/img/log-viewer-128.png": "/img/log-viewer-128.png?id=d576c6d2e16074d3f064e60fe4f35166",
"/img/log-viewer-32.png": "/img/log-viewer-32.png?id=f8ec67d10f996aa8baf00df3b61eea6d",
"/img/log-viewer-64.png": "/img/log-viewer-64.png?id=8902d596fc883ca9eb8105bb683568c6"
}

View File

@ -96,6 +96,10 @@
@endability
@endif
@ability('admin', 'logs')
<li><a href="{{ url('/admin/log-viewer') }}"><i class="pe-7s-note2"></i>logs</a></li>
@endability
@ability('admin', 'settings')
<li><a href="{{ url('/admin/settings') }}"><i class="pe-7s-config"></i>settings</a></li>
@endability