From 489669591a42961ffe56f6825db54e12b49caa1c Mon Sep 17 00:00:00 2001 From: FreeScout Date: Wed, 7 Nov 2018 01:38:31 -0800 Subject: [PATCH] Application logs --- .gitignore | 2 +- app/ActivityLog.php | 3 + app/Http/Controllers/SecureController.php | 1 + app/Http/Middleware/ResponseHeaders.php | 6 +- composer.json | 3 +- composer.lock | 71 +++++- config/app.php | 2 +- resources/views/layouts/app.blade.php | 2 +- .../vendor/laravel-log-viewer/log.blade.php | 234 ++++++++++++++++++ routes/web.php | 1 + 10 files changed, 313 insertions(+), 12 deletions(-) create mode 100644 resources/views/vendor/laravel-log-viewer/log.blade.php diff --git a/.gitignore b/.gitignore index 715dda5f..fcb2cc38 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ composer.phar #composer.lock .DS_Store Thumbs.db -/.htaccess +#/.htaccess /public/css/builds/ /public/js/builds/ /public/.well-known diff --git a/app/ActivityLog.php b/app/ActivityLog.php index d045cc3f..24879877 100644 --- a/app/ActivityLog.php +++ b/app/ActivityLog.php @@ -11,6 +11,7 @@ class ActivityLog extends Activity const NAME_EMAILS_SENDING = 'send_errors'; const NAME_EMAILS_FETCHING = 'fetch_errors'; const NAME_SYSTEM = 'system'; + const NAME_APP_LOGS = 'app'; const DESCRIPTION_USER_LOGIN = 'login'; const DESCRIPTION_USER_LOGOUT = 'logout'; @@ -83,6 +84,8 @@ class ActivityLog extends Activity return __('Fetch Errors'); case self::NAME_SYSTEM: return __('System'); + case self::NAME_APP_LOGS: + return __('App Logs'); default: return ucfirst($log_name); } diff --git a/app/Http/Controllers/SecureController.php b/app/Http/Controllers/SecureController.php index 9f19d1b3..457994d8 100644 --- a/app/Http/Controllers/SecureController.php +++ b/app/Http/Controllers/SecureController.php @@ -138,6 +138,7 @@ class SecureController extends Controller } array_unshift($names, ActivityLog::NAME_OUT_EMAILS); + array_push($names, ActivityLog::NAME_APP_LOGS); if (!in_array($name, $names)) { $names[] = $name; diff --git a/app/Http/Middleware/ResponseHeaders.php b/app/Http/Middleware/ResponseHeaders.php index 1fd0f2f1..06aeb738 100644 --- a/app/Http/Middleware/ResponseHeaders.php +++ b/app/Http/Middleware/ResponseHeaders.php @@ -11,8 +11,10 @@ class ResponseHeaders $response = $next($request); // Disable caching - $response->header('Pragma', 'no-cache'); - $response->header('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store'); + if (method_exists($response, 'header')) { + $response->header('Pragma', 'no-cache'); + $response->header('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store'); + } return $response; } diff --git a/composer.json b/composer.json index aa01477c..213c4c8d 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "barryvdh/laravel-translation-manager": "v0.5.0", "chumper/zipper": "v1.0.2", "rachidlaasri/laravel-installer": "4.0.2", - "kitetail/zttp": "v0.4.0" + "kitetail/zttp": "v0.4.0", + "rap2hpoutre/laravel-log-viewer": "v0.22.1" }, "require-dev": { "barryvdh/laravel-debugbar": "v2.4.3", diff --git a/composer.lock b/composer.lock index fc436961..aa8471c7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "f0bd9518872e95561e385b1738e8e6bd", + "content-hash": "0d4a209a58196e3d3e880a0cabc526cb", "packages": [ { "name": "anahkiasen/underscore-php", @@ -1385,16 +1385,16 @@ }, { "name": "monolog/monolog", - "version": "1.23.0", + "version": "1.24.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4" + "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4", - "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", + "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", "shasum": "" }, "require": { @@ -1459,7 +1459,7 @@ "logging", "psr-3" ], - "time": "2017-06-19T01:22:40+00:00" + "time": "2018-11-05T09:00:11+00:00" }, { "name": "mtdowling/cron-expression", @@ -2231,6 +2231,65 @@ ], "time": "2018-07-19T23:38:55+00:00" }, + { + "name": "rap2hpoutre/laravel-log-viewer", + "version": "v0.22.1", + "source": { + "type": "git", + "url": "https://github.com/rap2hpoutre/laravel-log-viewer.git", + "reference": "fd0821b073771f3e7256664417055a8bbb091059" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rap2hpoutre/laravel-log-viewer/zipball/fd0821b073771f3e7256664417055a8bbb091059", + "reference": "fd0821b073771f3e7256664417055a8bbb091059", + "shasum": "" + }, + "require": { + "illuminate/support": "4.2.*|5.*", + "php": ">=5.4.0" + }, + "require-dev": { + "orchestra/testbench": "^3.6", + "phpunit/phpunit": "^7" + }, + "type": "laravel-package", + "extra": { + "laravel": { + "providers": [ + "Rap2hpoutre\\LaravelLogViewer\\LaravelLogViewerServiceProvider" + ] + } + }, + "autoload": { + "classmap": [ + "src/controllers" + ], + "psr-0": { + "Rap2hpoutre\\LaravelLogViewer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "rap2hpoutre", + "email": "raphaelht@gmail.com" + } + ], + "description": "A Laravel log reader", + "keywords": [ + "laravel", + "log", + "log-reader", + "log-viewer", + "logging", + "lumen" + ], + "time": "2018-10-01T09:01:30+00:00" + }, { "name": "spatie/laravel-activitylog", "version": "2.7.0", diff --git a/config/app.php b/config/app.php index 10073ebd..3aaf387e 100644 --- a/config/app.php +++ b/config/app.php @@ -135,7 +135,7 @@ return [ | */ - 'log' => env('APP_LOG', 'single'), + 'log' => env('APP_LOG', 'daily'), // by default logs for 5 days are kept 'log_level' => env('APP_LOG_LEVEL', 'error'), diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 698d9fa6..b27ea16f 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -8,7 +8,7 @@ - @if ($__env->yieldContent('title_full')) @yield('title_full') @elseif ($__env->yieldContent('title')) @yield('title') - {{ config('app.name', 'FreeScout') }} @else {{ config('app.name', 'FreeScout') }} @endif + @if ($__env->yieldContent('title_full'))@yield('title_full') @elseif ($__env->yieldContent('title'))@yield('title') - {{ config('app.name', 'FreeScout') }} @else{{ config('app.name', 'FreeScout') }}@endif {{-- diff --git a/resources/views/vendor/laravel-log-viewer/log.blade.php b/resources/views/vendor/laravel-log-viewer/log.blade.php new file mode 100644 index 00000000..145f635f --- /dev/null +++ b/resources/views/vendor/laravel-log-viewer/log.blade.php @@ -0,0 +1,234 @@ +@extends('layouts.app') + +@section('title', __('Logs')) + +@section('sidebar') + @include('partials/sidebar_menu_toggle') + + @php + $names = App\ActivityLog::select('log_name')->distinct()->pluck('log_name')->toArray(); + array_unshift($names, App\ActivityLog::NAME_OUT_EMAILS); + array_push($names, App\ActivityLog::NAME_APP_LOGS); + $current_name = 'app'; + @endphp + +@endsection + +@section('content') + + + +
+ {{ __('Log Records') }} +
+ +
+
+ +
+ @if ($logs === null) +
+ Log file >50M, please download it. +
+ @else + + + + @if ($standardFormat) + + + + @else + + @endif + + + + + + @foreach($logs as $key => $log) + + @if ($standardFormat) + + + @endif + + + + @endforeach + + +
LevelContextDateLine numberContent
+   {{$log['level']}} + {{$log['context']}}{{{$log['date']}}} + @if ($log['stack']) + + @endif + {{{$log['text']}}} + @if (isset($log['in_file'])) +
{{{$log['in_file']}}} + @endif + @if ($log['stack']) + + @endif +
+ @endif +
+ @if($current_file) + + Download file + + {{--- + + Clean file + --}} + - + + Delete file + + @if(count($files) > 1) + - + + Delete all files + + @endif + @endif +
+
+
+
+ + + + + + + + + +@endsection + +@section('stylesheets') + +@endsection + +@section('javascripts') + +@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 35905032..e90f3b66 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,6 +24,7 @@ Route::post('/user-setup/{hash}', 'PublicController@userSetupSave'); // General routes for logged in users Route::get('/', 'SecureController@dashboard')->name('dashboard'); +Route::get('/logs/app', ['uses' => '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index', 'middleware' => ['auth', 'roles'], 'roles' => ['admin']])->name('logs.app'); Route::get('/logs/{name?}', ['uses' => 'SecureController@logs', 'middleware' => ['auth', 'roles'], 'roles' => ['admin']])->name('logs'); Route::post('/logs/{name?}', ['uses' => 'SecureController@logsSubmit', 'middleware' => ['auth', 'roles'], 'roles' => ['admin']]);