Skip to content

Commit 10ed3d0

Browse files
committed
First commit
1 parent 141bd3a commit 10ed3d0

File tree

12 files changed

+224
-0
lines changed

12 files changed

+224
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
laravel
5+
.DS_Store
6+
.idea

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "rap2hpoutre/laravel-log-viewer",
3+
"description": "",
4+
"authors": [
5+
{
6+
"name": "rap2hpoutre",
7+
"email": "[email protected]"
8+
}
9+
],
10+
"require": {
11+
"php": ">=5.4.0",
12+
"illuminate/support": "4.2.*"
13+
},
14+
"autoload": {
15+
"classmap": [
16+
"src/migrations",
17+
"src/controllers"
18+
],
19+
"psr-0": {
20+
"Rap2hpoutre\\LaravelLogViewer\\": "src/"
21+
}
22+
},
23+
"minimum-stability": "stable"
24+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
namespace Rap2hpoutre\LaravelLogViewer;
3+
4+
use Illuminate\Support\Facades\File;
5+
use Psr\Log\LogLevel;
6+
use ReflectionClass;
7+
8+
class LaravelLogViewer
9+
{
10+
public static function all()
11+
{
12+
$log = array();
13+
14+
$class = new ReflectionClass(new LogLevel);
15+
$log_levels = $class->getConstants();
16+
17+
$pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/';
18+
19+
$log_file = storage_path() . '/logs/laravel.log';
20+
21+
$file = File::get($log_file);
22+
23+
preg_match_all($pattern, $file, $headings);
24+
25+
$log_data = preg_split($pattern, $file);
26+
27+
if ($log_data[0] < 1) {
28+
$trash = array_shift($log_data);
29+
unset($trash);
30+
}
31+
32+
foreach ($headings as $h) {
33+
for ($i=0, $j = count($h); $i < $j; $i++) {
34+
foreach ($log_levels as $ll) {
35+
if (strpos(strtolower($h[$i]), strtolower('.'.$ll))) {
36+
37+
$level = strtoupper($ll);
38+
39+
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
40+
41+
$log[] = array(
42+
'level' => $ll,
43+
'date' => $current[1],
44+
'text' => $current[2],
45+
'in_file' => isset($current[3]) ? $current[3] : null,
46+
'stack' => $log_data[$i]
47+
);
48+
}
49+
}
50+
}
51+
}
52+
53+
$log = array_reverse($log);
54+
return $log;
55+
}
56+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php namespace Rap2hpoutre\LaravelLogViewer;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
5+
class LaravelLogViewerServiceProvider extends ServiceProvider {
6+
7+
/**
8+
* Indicates if loading of the provider is deferred.
9+
*
10+
* @var bool
11+
*/
12+
protected $defer = false;
13+
14+
/**
15+
* Bootstrap the application events.
16+
*
17+
* @return void
18+
*/
19+
public function boot()
20+
{
21+
$this->package('rap2hpoutre/laravel-log-viewer', null, __DIR__);
22+
}
23+
24+
/**
25+
* Register the service provider.
26+
*
27+
* @return void
28+
*/
29+
public function register()
30+
{
31+
//
32+
}
33+
34+
/**
35+
* Get the services provided by the provider.
36+
*
37+
* @return array
38+
*/
39+
public function provides()
40+
{
41+
return array();
42+
}
43+
44+
}

src/config/.gitkeep

Whitespace-only changes.

src/controllers/.gitkeep

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace Rap2hpoutre\LaravelLogViewer;
3+
4+
use Illuminate\Support\Facades\View;
5+
6+
class LogViewerController extends \BaseController
7+
{
8+
9+
public function index()
10+
{
11+
$logs = LaravelLogViewer::all();
12+
View::addNamespace('laravel-log-viewer', __DIR__.'../../views');
13+
return View::make('laravel-log-viewer::log', ['logs' => $logs]);
14+
}
15+
16+
}

src/lang/.gitkeep

Whitespace-only changes.

src/views/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)