-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
141bd3a
commit 10ed3d0
Showing
12 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
laravel | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "rap2hpoutre/laravel-log-viewer", | ||
"description": "", | ||
"authors": [ | ||
{ | ||
"name": "rap2hpoutre", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/support": "4.2.*" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
"src/migrations", | ||
"src/controllers" | ||
], | ||
"psr-0": { | ||
"Rap2hpoutre\\LaravelLogViewer\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
namespace Rap2hpoutre\LaravelLogViewer; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Psr\Log\LogLevel; | ||
use ReflectionClass; | ||
|
||
class LaravelLogViewer | ||
{ | ||
public static function all() | ||
{ | ||
$log = array(); | ||
|
||
$class = new ReflectionClass(new LogLevel); | ||
$log_levels = $class->getConstants(); | ||
|
||
$pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/'; | ||
|
||
$log_file = storage_path() . '/logs/laravel.log'; | ||
|
||
$file = File::get($log_file); | ||
|
||
preg_match_all($pattern, $file, $headings); | ||
|
||
$log_data = preg_split($pattern, $file); | ||
|
||
if ($log_data[0] < 1) { | ||
$trash = array_shift($log_data); | ||
unset($trash); | ||
} | ||
|
||
foreach ($headings as $h) { | ||
for ($i=0, $j = count($h); $i < $j; $i++) { | ||
foreach ($log_levels as $ll) { | ||
if (strpos(strtolower($h[$i]), strtolower('.'.$ll))) { | ||
|
||
$level = strtoupper($ll); | ||
|
||
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current); | ||
|
||
$log[] = array( | ||
'level' => $ll, | ||
'date' => $current[1], | ||
'text' => $current[2], | ||
'in_file' => isset($current[3]) ? $current[3] : null, | ||
'stack' => $log_data[$i] | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
$log = array_reverse($log); | ||
return $log; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php namespace Rap2hpoutre\LaravelLogViewer; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class LaravelLogViewerServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->package('rap2hpoutre/laravel-log-viewer', null, __DIR__); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array(); | ||
} | ||
|
||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
namespace Rap2hpoutre\LaravelLogViewer; | ||
|
||
use Illuminate\Support\Facades\View; | ||
|
||
class LogViewerController extends \BaseController | ||
{ | ||
|
||
public function index() | ||
{ | ||
$logs = LaravelLogViewer::all(); | ||
View::addNamespace('laravel-log-viewer', __DIR__.'../../views'); | ||
return View::make('laravel-log-viewer::log', ['logs' => $logs]); | ||
} | ||
|
||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Laravel log viewer</title> | ||
|
||
<!-- Bootstrap --> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> | ||
|
||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> | ||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | ||
<!--[if lt IE 9]> | ||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> | ||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | ||
<![endif]--> | ||
</head> | ||
<body> | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-3 col-md-2 sidebar"> | ||
<p>Todo</p> | ||
</div> | ||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> | ||
<div class="table-responsive"> | ||
<div class="table-responsive"> | ||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Level</th> | ||
<th>Date</th> | ||
<th>Content</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach($logs as $log) | ||
<tr> | ||
<td>{{{$log['level']}}}</td> | ||
<td>{{{$log['date']}}}</td> | ||
<td> | ||
{{{$log['text']}}} | ||
@if (isset($log['in_file'])) | ||
<br />{{{$log['in_file']}}} | ||
@endif | ||
</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | ||
</body> | ||
</html> |
Empty file.