Browse Source
Added laravel log files viewer
Added laravel log files viewer
Changed log setting to daily to get daily log files Changed log_max_files to 30 to view last 30 days log filespull/6/head
5 changed files with 115 additions and 1 deletions
-
37app/Http/Controllers/LogFilesController.php
-
4config/app.php
-
2resources/views/layouts/partials/top-nav.blade.php
-
66resources/views/log-files.blade.php
-
7routes/web.php
@ -0,0 +1,37 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers; |
|||
|
|||
use Illuminate\Http\Request; |
|||
|
|||
class LogFilesController extends Controller |
|||
{ |
|||
public function index() { |
|||
|
|||
if (!file_exists(storage_path('logs'))) |
|||
return []; |
|||
|
|||
$logFiles = \File::allFiles(storage_path('logs')); |
|||
|
|||
// Sort files by modified time DESC
|
|||
usort($logFiles, function($a, $b) { |
|||
return -1 * strcmp($a->getMTime(), $b->getMTime()); |
|||
}); |
|||
|
|||
return view('log-files',compact('logFiles')); |
|||
} |
|||
|
|||
public function show($fileName) { |
|||
if (file_exists(storage_path('logs/' . $fileName))) |
|||
return response()->file(storage_path('logs/' . $fileName), ['content-type' => 'text/plain']); |
|||
|
|||
return 'Invalid file name.'; |
|||
} |
|||
|
|||
public function download($fileName) { |
|||
if (file_exists(storage_path('logs/' . $fileName))) |
|||
return response()->download(storage_path('logs/' . $fileName), env('APP_ENV') . '.' . $fileName); |
|||
|
|||
return 'Invalid file name.'; |
|||
} |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title','Log Files') |
|||
|
|||
@section('content') |
|||
<h3 class="page-header">Application Log Files</h3> |
|||
<div class="row"> |
|||
<div class="col-md-8"> |
|||
<div class="panel panel-default"> |
|||
<table class="table table-condensed"> |
|||
<thead> |
|||
<th>#</th>
|
|||
<th>File Name</th> |
|||
<th>Size</th> |
|||
<th>Time</th> |
|||
<th>{{ trans('app.action') }}</th> |
|||
</thead> |
|||
<tbody> |
|||
@if (File::exists('error_log')) |
|||
<tr> |
|||
<td>0</td> |
|||
<td>error_log</td> |
|||
<td>{{ formatSizeUnits(File::size('error_log')) }}</td> |
|||
<td>{{ date('Y-m-d H:i:s', File::lastModified('error_log')) }}</td> |
|||
<td> |
|||
{!! html_link_to_route('log-files.server-error-log','',[],[ |
|||
'class'=>'btn btn-default btn-xs', |
|||
'icon' => 'search', |
|||
'id' => 'view-error-log', |
|||
'title' => 'View file error_log', |
|||
'target' => '_blank', |
|||
]) !!} |
|||
</td> |
|||
</tr> |
|||
@endif |
|||
@forelse($logFiles as $key => $logFile) |
|||
<tr> |
|||
<td>{{ $key + 1 }}</td> |
|||
<td>{{ $logFile->getFilename() }}</td> |
|||
<td>{{ formatSizeUnits($logFile->getSize()) }}</td> |
|||
<td>{{ date('Y-m-d H:i:s', $logFile->getMTime()) }}</td> |
|||
<td> |
|||
{{ link_to_route('log-files.show', 'Lihat', [$logFile->getFilename()],[ |
|||
'class'=>'btn btn-default btn-xs', |
|||
'id' => 'view-' . $logFile->getFilename(), |
|||
'title' => 'View file ' . $logFile->getFilename(), |
|||
'target' => '_blank' |
|||
]) }} |
|||
{{ link_to_route('log-files.download', 'Download', [$logFile->getFilename()],[ |
|||
'class'=>'btn btn-default btn-xs', |
|||
'id' => 'download-' . $logFile->getFilename(), |
|||
'title' => 'Download file ' . $logFile->getFilename() |
|||
]) }} |
|||
</td> |
|||
</tr> |
|||
@empty |
|||
<tr> |
|||
<td colspan="3">No Log File Exists</td> |
|||
</tr> |
|||
@endforelse |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue