Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre committed Nov 23, 2014
1 parent 141bd3a commit 10ed3d0
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/vendor
composer.phar
composer.lock
laravel
.DS_Store
.idea
24 changes: 24 additions & 0 deletions composer.json
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"
}
18 changes: 18 additions & 0 deletions phpunit.xml
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>
56 changes: 56 additions & 0 deletions src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
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;
}
}
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 added src/config/.gitkeep
Empty file.
Empty file added src/controllers/.gitkeep
Empty file.
16 changes: 16 additions & 0 deletions src/controllers/LogViewerController.php
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 added src/lang/.gitkeep
Empty file.
Empty file added src/views/.gitkeep
Empty file.
60 changes: 60 additions & 0 deletions src/views/log.blade.php
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 added tests/.gitkeep
Empty file.

0 comments on commit 10ed3d0

Please sign in to comment.