Repository: rap2hpoutre/laravel-log-viewer
Branch: master
Commit: ab85d5d88de7
Files: 15
Total size: 43.6 KB
Directory structure:
gitextract_pf84q1ng/
├── .github/
│ └── workflows/
│ └── run-tests.yml
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── phpunit.xml
├── src/
│ ├── Rap2hpoutre/
│ │ └── LaravelLogViewer/
│ │ ├── LaravelLogViewer.php
│ │ ├── LaravelLogViewerServiceProvider.php
│ │ ├── Level.php
│ │ └── Pattern.php
│ ├── config/
│ │ └── logviewer.php
│ ├── controllers/
│ │ └── LogViewerController.php
│ └── views/
│ └── log.blade.php
└── tests/
├── LaravelLogViewerTest.php
└── laravel.log
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/run-tests.yml
================================================
name: Tests
on:
push:
pull_request:
jobs:
tests:
strategy:
fail-fast: true
matrix:
php: ["7.2", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]
laravel: ["^6.0", "^7.0", "^8.0", "^9.0", "^10.0", "^11.0", "^12.0"]
exclude:
- php: "8.0"
laravel: "^10.0"
- php: "7.4"
laravel: "^10.0"
- php: "7.2"
laravel: "^10.0"
- php: "7.4"
laravel: "^9.0"
- php: "7.2"
laravel: "^9.0"
- php: "8.4"
laravel: "^8.0"
- php: "8.3"
laravel: "^8.0"
- php: "8.2"
laravel: "^8.0"
- php: "7.2"
laravel: "^8.0"
- php: "8.4"
laravel: "^7.0"
- php: "8.3"
laravel: "^7.0"
- php: "8.2"
laravel: "^7.0"
- php: "8.1"
laravel: "^7.0"
- php: "8.4"
laravel: "^6.0"
- php: "8.3"
laravel: "^6.0"
- php: "8.2"
laravel: "^6.0"
- php: "8.1"
laravel: "^6.0"
- php: "7.2"
laravel: "^11.0"
- php: "7.4"
laravel: "^11.0"
- php: "8.0"
laravel: "^11.0"
- php: "8.1"
laravel: "^11.0"
- php: "7.2"
laravel: "^12.0"
- php: "7.4"
laravel: "^12.0"
- php: "8.0"
laravel: "^12.0"
- php: "8.1"
laravel: "^12.0"
name: "PHP${{ matrix.php }} - Laravel${{ matrix.laravel }}"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"
- name: "Setup PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
extensions: "dom, curl, libxml, mbstring, zip, fileinfo"
tools: "composer:v2"
coverage: "none"
- name: "Check Composer configuration"
run: "composer validate --strict"
- name: "Install dependencies from composer.json"
run: "composer update --with='laravel/framework:${{ matrix.laravel }}' --no-interaction --no-progress"
- name: "Check PSR-4 mapping"
run: "composer dump-autoload --optimize --strict-psr"
- name: "Execute unit tests"
run: "vendor/bin/phpunit"
================================================
FILE: .gitignore
================================================
/vendor
composer.lock
/.idea
/build
.phpunit.result.cache
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2014-present rap2hpoutre
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
Laravel log viewer
==================
[](https://packagist.org/packages/rap2hpoutre/laravel-log-viewer)
[](https://packagist.org/packages/rap2hpoutre/laravel-log-viewer)
[](https://packagist.org/packages/rap2hpoutre/laravel-log-viewer)
[](https://scrutinizer-ci.com/g/rap2hpoutre/laravel-log-viewer/?branch=master)
[](https://twitter.com/rap2h)
## TL;DR
Log Viewer for Laravel 6, 7, 8, 9, 10, 11 & 12 and Lumen. **Install with composer, create a route to `LogViewerController`**. No public assets, no vendor routes, works with and/or without log rotate. Inspired by Micheal Mand's [Laravel 4 log viewer](https://github.com/mikemand/logviewer) (works only with laravel 4.1)
## What ?
Small log viewer for laravel. Looks like this:

## Install (Laravel)
Install via composer
```bash
composer require rap2hpoutre/laravel-log-viewer
```
Add Service Provider to `config/app.php` in `providers` section
```php
Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class,
```
Add a route in your web routes file:
```php
Route::get('logs', [\Rap2hpoutre\LaravelLogViewer\LogViewerController::class, 'index']);
```
Go to `http://myapp/logs` or some other route
### Install (Lumen)
Install via composer
```bash
composer require rap2hpoutre/laravel-log-viewer
```
Add the following in `bootstrap/app.php`:
```php
$app->register(\Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class);
```
Explicitly set the namespace in `app/Http/routes.php`:
```php
$router->group(['namespace' => '\Rap2hpoutre\LaravelLogViewer'], function() use ($router) {
$router->get('logs', 'LogViewerController@index');
});
```
## Advanced usage
### Customize view
Publish `log.blade.php` into `/resources/views/vendor/laravel-log-viewer/` for view customization:
```bash
php artisan vendor:publish \
--provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider" \
--tag=views
```
### Edit configuration
Publish `logviewer.php` configuration file into `/config/` for configuration customization:
```bash
php artisan vendor:publish \
--provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider"
```
### Troubleshooting
If you got a `InvalidArgumentException in FileViewFinder.php` error, it may be a problem with config caching. Double check installation, then run `php artisan config:clear`.
================================================
FILE: composer.json
================================================
{
"name": "rap2hpoutre/laravel-log-viewer",
"description": "A Laravel log reader",
"license": "MIT",
"keywords": [
"log",
"log-reader",
"log-viewer",
"logging",
"laravel",
"lumen"
],
"type": "laravel-package",
"authors": [
{
"name": "rap2hpoutre",
"email": "raphaelht@gmail.com"
}
],
"require": {
"php": "^7.2|^8.0",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0"
},
"require-dev": {
"phpunit/phpunit": "^7||^8.4|^9.3.3|^10.1|^11.0",
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0|^9.0|^10.0"
},
"autoload": {
"classmap": [
"src/controllers"
],
"psr-0": {
"Rap2hpoutre\\LaravelLogViewer\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rap2hpoutre\\LaravelLogViewer\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Rap2hpoutre\\LaravelLogViewer\\LaravelLogViewerServiceProvider"
]
}
},
"minimum-stability": "stable"
}
================================================
FILE: phpunit.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="all">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
</phpunit>
================================================
FILE: src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
================================================
<?php
namespace Rap2hpoutre\LaravelLogViewer;
class LaravelLogViewer
{
/**
* @var string file
*/
private $file = '';
/**
* @var string folder
*/
private $folder = '';
/**
* @var string storage_path
*/
private $storage_path;
/**
* Why? Uh... Sorry
*/
const MAX_FILE_SIZE = 52428800;
/**
* @var Level level
*/
private $level;
/**
* @var Pattern pattern
*/
private $pattern;
/**
* LaravelLogViewer constructor.
*/
public function __construct()
{
$this->level = new Level();
$this->pattern = new Pattern();
$this->storage_path = function_exists('config') ? config('logviewer.storage_path', storage_path('logs')) : storage_path('logs');
}
/**
* @param string $folder
*/
public function setFolder($folder)
{
if (app('files')->exists($folder)) {
$this->folder = $folder;
} else if (is_array($this->storage_path)) {
foreach ($this->storage_path as $value) {
$logsPath = $value . '/' . $folder;
if (app('files')->exists($logsPath)) {
$this->folder = $folder;
break;
}
}
} else {
$logsPath = $this->storage_path . '/' . $folder;
if (app('files')->exists($logsPath)) {
$this->folder = $folder;
}
}
}
/**
* @param string $file
* @throws \Exception
*/
public function setFile($file)
{
$file = $this->pathToLogFile($file);
if (app('files')->exists($file)) {
$this->file = $file;
}
}
/**
* @param string $file
* @return string
* @throws \Exception
*/
public function pathToLogFile($file)
{
if (app('files')->exists($file)) { // try the absolute path
return $file;
}
if (is_array($this->storage_path)) {
foreach ($this->storage_path as $folder) {
if (app('files')->exists($folder . '/' . $file)) { // try the absolute path
$file = $folder . '/' . $file;
break;
}
}
return $file;
}
$logsPath = $this->storage_path;
$logsPath .= ($this->folder) ? '/' . $this->folder : '';
$file = $logsPath . '/' . $file;
// check if requested file is really in the logs directory
if (dirname($file) !== $logsPath) {
throw new \Exception('No such log file: ' . $file);
}
return $file;
}
/**
* @return string
*/
public function getFolderName()
{
return $this->folder;
}
/**
* @return string
*/
public function getFileName()
{
return basename($this->file);
}
/**
* @return array
*/
public function all()
{
$log = array();
if (!$this->file) {
$log_file = (!$this->folder) ? $this->getFiles() : $this->getFolderFiles();
if (!count($log_file)) {
return [];
}
$this->file = $log_file[0];
}
$max_file_size = function_exists('config') ? config('logviewer.max_file_size', self::MAX_FILE_SIZE) : self::MAX_FILE_SIZE;
if (app('files')->size($this->file) > $max_file_size) {
return null;
}
if (!is_readable($this->file)) {
return [[
'context' => '',
'level' => '',
'date' => null,
'text' => 'Log file "' . $this->file . '" not readable',
'stack' => '',
]];
}
$file = app('files')->get($this->file);
preg_match_all($this->pattern->getPattern('logs'), $file, $headings);
if (!is_array($headings)) {
return $log;
}
$log_data = preg_split($this->pattern->getPattern('logs'), $file);
if ($log_data[0] < 1) {
array_shift($log_data);
}
foreach ($headings as $h) {
for ($i = 0, $j = count($h); $i < $j; $i++) {
foreach ($this->level->all() as $level) {
if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) {
preg_match($this->pattern->getPattern('current_log', 0) . $level . $this->pattern->getPattern('current_log', 1), $h[$i], $current);
if (!isset($current[4])) {
continue;
}
$log[] = array(
'context' => $current[3],
'level' => $level,
'folder' => $this->folder,
'level_class' => $this->level->cssClass($level),
'level_img' => $this->level->img($level),
'date' => $current[1],
'text' => $current[4],
'in_file' => isset($current[5]) ? $current[5] : null,
'stack' => preg_replace("/^\n*/", '', $log_data[$i])
);
}
}
}
}
if (empty($log)) {
$lines = explode(PHP_EOL, $file);
$log = [];
foreach ($lines as $key => $line) {
$log[] = [
'context' => '',
'level' => '',
'folder' => '',
'level_class' => '',
'level_img' => '',
'date' => $key + 1,
'text' => $line,
'in_file' => null,
'stack' => '',
];
}
}
return array_reverse($log);
}
/**Creates a multidimensional array
* of subdirectories and files
*
* @param null $path
*
* @return array
*/
public function foldersAndFiles($path = null)
{
$contents = array();
$dir = $path ? $path : $this->storage_path;
foreach (scandir($dir) as $node) {
if ($node == '.' || $node == '..') continue;
$path = $dir . '\\' . $node;
if (is_dir($path)) {
$contents[$path] = $this->foldersAndFiles($path);
} else {
$contents[] = $path;
}
}
return $contents;
}
/**Returns an array of
* all subdirectories of specified directory
*
* @param string $folder
*
* @return array
*/
public function getFolders($folder = '')
{
$folders = [];
$listObject = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->storage_path . '/' . $folder, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($listObject as $fileinfo) {
if ($fileinfo->isDir()) $folders[] = $fileinfo->getRealPath();
}
return $folders;
}
/**
* @param bool $basename
* @return array
*/
public function getFolderFiles($basename = false)
{
return $this->getFiles($basename, $this->folder);
}
/**
* @param bool $basename
* @param string $folder
* @return array
*/
public function getFiles($basename = false, $folder = '')
{
$files = [];
$pattern = function_exists('config') ? config('logviewer.pattern', '*.log') : '*.log';
$fullPath = $this->storage_path . '/' . $folder;
$listObject = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($fullPath, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($listObject as $fileinfo) {
if (!$fileinfo->isDir() && strtolower(pathinfo($fileinfo->getRealPath(), PATHINFO_EXTENSION)) == explode('.', $pattern)[1])
$files[] = $basename ? basename($fileinfo->getRealPath()) : $fileinfo->getRealPath();
}
arsort($files);
return array_values($files);
}
/**
* @return string
*/
public function getStoragePath()
{
return $this->storage_path;
}
/**
* @param $path
*
* @return void
*/
public function setStoragePath($path)
{
$this->storage_path = $path;
}
public static function directoryTreeStructure($storage_path, array $array)
{
foreach ($array as $k => $v) {
if (is_dir($k)) {
$exploded = explode("\\", $k);
$show = last($exploded);
echo '<div class="list-group folder">
<a href="?f=' . \Illuminate\Support\Facades\Crypt::encrypt($k) . '">
<span> </span><span
class="fa fa-folder"></span> ' . $show . '
</a>
</div>';
if (is_array($v)) {
self::directoryTreeStructure($storage_path, $v);
}
} else {
$exploded = explode("\\", $v);
$show2 = last($exploded);
$folder = str_replace($storage_path, "", rtrim(str_replace($show2, "", $v), "\\"));
$file = $v;
echo '<div class="list-group">
<a href="?l=' . \Illuminate\Support\Facades\Crypt::encrypt($file) . '&f=' . \Illuminate\Support\Facades\Crypt::encrypt($folder) . '">
<span> </span> <span
class="fa fa-file"></span> ' . $show2 . '
</a>
</div>';
}
}
return;
}
}
================================================
FILE: src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php
================================================
<?php
namespace Rap2hpoutre\LaravelLogViewer;
use Illuminate\Support\ServiceProvider;
class LaravelLogViewerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
if (method_exists($this, 'package')) {
$this->package('rap2hpoutre/laravel-log-viewer', 'laravel-log-viewer', __DIR__.'/../../');
}
if (method_exists($this, 'loadViewsFrom')) {
$this->loadViewsFrom(__DIR__.'/../../views', 'laravel-log-viewer');
}
if (method_exists($this, 'publishes')) {
$this->publishes([
__DIR__.'/../../views' => base_path('/resources/views/vendor/laravel-log-viewer'),
], 'views');
$this->publishes([
__DIR__.'/../../config/logviewer.php' => $this->config_path('logviewer.php'),
]);
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
/**
* Get the configuration path.
*
* @param string $path
* @return string
*/
private function config_path($path = '')
{
return function_exists('config_path') ? config_path($path) : app()->basePath().DIRECTORY_SEPARATOR.'config'.($path ? DIRECTORY_SEPARATOR.$path : $path);
}
}
================================================
FILE: src/Rap2hpoutre/LaravelLogViewer/Level.php
================================================
<?php
namespace Rap2hpoutre\LaravelLogViewer;
/**
* Class Level
* @package Rap2hpoutre\LaravelLogViewer
*/
class Level
{
/**
* @var array<string, string>
*/
private $levelsClasses = [
'debug' => 'info',
'info' => 'info',
'notice' => 'info',
'warning' => 'warning',
'error' => 'danger',
'critical' => 'danger',
'alert' => 'danger',
'emergency' => 'danger',
'processed' => 'info',
'failed' => 'warning',
];
/**
* @var array<string, string>
*/
private $icons = [
'debug' => 'info-circle',
'info' => 'info-circle',
'notice' => 'info-circle',
'warning' => 'exclamation-triangle',
'error' => 'exclamation-triangle',
'critical' => 'exclamation-triangle',
'alert' => 'exclamation-triangle',
'emergency' => 'exclamation-triangle',
'processed' => 'info-circle',
'failed' => 'exclamation-triangle'
];
/**
* @return string[]
*/
public function all()
{
return array_keys($this->icons);
}
/**
* @param string $level
* @return string
*/
public function img($level)
{
return $this->icons[$level];
}
/**
* @param string $level
* @return string
*/
public function cssClass($level)
{
return $this->levelsClasses[$level];
}
}
================================================
FILE: src/Rap2hpoutre/LaravelLogViewer/Pattern.php
================================================
<?php
namespace Rap2hpoutre\LaravelLogViewer;
class Pattern
{
/**
* @var array<string, string>
*/
private $patterns = [
'logs' => '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/',
'current_log' => [
'/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?)\](?:.*?(\w+)\.|.*?)',
': (.*?)( in .*?:[0-9]+)?$/i'
],
'files' => '/\{.*?\,.*?\}/i',
];
/**
* @return string[]
*/
public function all()
{
return array_keys($this->patterns);
}
/**
* @param string $pattern
* @param null|string $position
* @return string pattern
*/
public function getPattern($pattern, $position = null)
{
if ($position !== null) {
return $this->patterns[$pattern][$position];
}
return $this->patterns[$pattern];
}
}
================================================
FILE: src/config/logviewer.php
================================================
<?php
return [
/*
|--------------------------------------------------------------------------
| Pattern and storage path settings
|--------------------------------------------------------------------------
|
| The env key for pattern and storage path with a default value
|
*/
'max_file_size' => 52428800, // size in Byte
'pattern' => env('LOGVIEWER_PATTERN', '*.log'),
'storage_path' => env('LOGVIEWER_STORAGE_PATH', storage_path('logs')),
];
================================================
FILE: src/controllers/LogViewerController.php
================================================
<?php
namespace Rap2hpoutre\LaravelLogViewer;
use Illuminate\Support\Facades\Crypt;
if (class_exists("\\Illuminate\\Routing\\Controller")) {
class BaseController extends \Illuminate\Routing\Controller {}
} elseif (class_exists("Laravel\\Lumen\\Routing\\Controller")) {
class BaseController extends \Laravel\Lumen\Routing\Controller {}
}
/**
* Class LogViewerController
* @package Rap2hpoutre\LaravelLogViewer
*/
class LogViewerController extends BaseController
{
/**
* @var \Illuminate\Http\Request
*/
protected $request;
/**
* @var LaravelLogViewer
*/
private $log_viewer;
/**
* @var string
*/
protected $view_log = 'laravel-log-viewer::log';
/**
* LogViewerController constructor.
*/
public function __construct()
{
$this->log_viewer = new LaravelLogViewer();
$this->request = app('request');
}
/**
* @return array|mixed
* @throws \Exception
*/
public function index()
{
$folderFiles = [];
if ($this->request->input('f')) {
$this->log_viewer->setFolder(Crypt::decrypt($this->request->input('f')));
$folderFiles = $this->log_viewer->getFolderFiles(true);
}
if ($this->request->input('l')) {
$this->log_viewer->setFile(Crypt::decrypt($this->request->input('l')));
}
if ($early_return = $this->earlyReturn()) {
return $early_return;
}
$data = [
'logs' => $this->log_viewer->all(),
'folders' => $this->log_viewer->getFolders(),
'current_folder' => $this->log_viewer->getFolderName(),
'folder_files' => $folderFiles,
'files' => $this->log_viewer->getFiles(true),
'current_file' => $this->log_viewer->getFileName(),
'standardFormat' => true,
'structure' => $this->log_viewer->foldersAndFiles(),
'storage_path' => $this->log_viewer->getStoragePath(),
];
if ($this->request->wantsJson()) {
return $data;
}
if (is_array($data['logs']) && count($data['logs']) > 0) {
$firstLog = reset($data['logs']);
if ($firstLog) {
if (!$firstLog['context'] && !$firstLog['level']) {
$data['standardFormat'] = false;
}
}
}
return app('view')->make($this->view_log, $data);
}
/**
* @return bool|mixed
* @throws \Exception
*/
private function earlyReturn()
{
if ($this->request->input('f')) {
$this->log_viewer->setFolder(Crypt::decrypt($this->request->input('f')));
}
if ($this->request->input('dl')) {
return $this->download($this->pathFromInput('dl'));
} elseif ($this->request->has('clean')) {
app('files')->put($this->pathFromInput('clean'), '');
return $this->redirect(url()->previous());
} elseif ($this->request->has('del')) {
app('files')->delete($this->pathFromInput('del'));
return $this->redirect($this->request->url());
} elseif ($this->request->has('delall')) {
$files = ($this->log_viewer->getFolderName())
? $this->log_viewer->getFolderFiles(true)
: $this->log_viewer->getFiles(true);
foreach ($files as $file) {
app('files')->delete($this->log_viewer->pathToLogFile($file));
}
return $this->redirect($this->request->url());
}
return false;
}
/**
* @param string $input_string
* @return string
* @throws \Exception
*/
private function pathFromInput($input_string)
{
return $this->log_viewer->pathToLogFile(Crypt::decrypt($this->request->input($input_string)));
}
/**
* @param $to
* @return mixed
*/
private function redirect($to)
{
if (function_exists('redirect')) {
return redirect($to);
}
return app('redirect')->to($to);
}
/**
* @param string $data
* @return mixed
*/
private function download($data)
{
if (function_exists('response')) {
return response()->download($data);
}
// For laravel 4.2
return app('\Illuminate\Support\Facades\Response')->download($data);
}
}
================================================
FILE: src/views/log.blade.php
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="robots" content="noindex, nofollow">
<title>Laravel log viewer</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css">
<style>
body {
padding: 25px;
}
h1 {
font-size: 1.5em;
margin-top: 0;
}
#table-log {
font-size: 0.85rem;
}
.sidebar {
font-size: 0.85rem;
line-height: 1;
}
.btn {
font-size: 0.7rem;
}
.stack {
font-size: 0.85em;
}
.date {
min-width: 75px;
}
.text {
word-break: break-all;
}
a.llv-active {
z-index: 2;
background-color: #f5f5f5;
border-color: #777;
}
.list-group-item {
word-break: break-word;
}
.folder {
padding-top: 15px;
}
.div-scroll {
height: 80vh;
overflow: hidden auto;
}
.nowrap {
white-space: nowrap;
}
.list-group {
padding: 5px;
}
/**
* DARK MODE CSS
*/
body[data-theme="dark"] {
background-color: #151515;
color: #cccccc;
}
[data-theme="dark"] a {
color: #4da3ff;
}
[data-theme="dark"] a:hover {
color: #a8d2ff;
}
[data-theme="dark"] .list-group-item {
background-color: #1d1d1d;
border-color: #444;
}
[data-theme="dark"] a.llv-active {
background-color: #0468d2;
border-color: rgba(255, 255, 255, 0.125);
color: #ffffff;
}
[data-theme="dark"] a.list-group-item:focus, [data-theme="dark"] a.list-group-item:hover {
background-color: #273a4e;
border-color: rgba(255, 255, 255, 0.125);
color: #ffffff;
}
[data-theme="dark"] .table td, [data-theme="dark"] .table th,[data-theme="dark"] .table thead th {
border-color:#616161;
}
[data-theme="dark"] .page-item.disabled .page-link {
color: #8a8a8a;
background-color: #151515;
border-color: #5a5a5a;
}
[data-theme="dark"] .page-link {
background-color: #151515;
border-color: #5a5a5a;
}
[data-theme="dark"] .page-item.active .page-link {
color: #fff;
background-color: #0568d2;
border-color: #007bff;
}
[data-theme="dark"] .page-link:hover {
color: #ffffff;
background-color: #0051a9;
border-color: #0568d2;
}
[data-theme="dark"] .form-control {
border: 1px solid #464646;
background-color: #151515;
color: #bfbfbf;
}
[data-theme="dark"] .form-control:focus {
color: #bfbfbf;
background-color: #212121;
border-color: #4a4a4a;
}
</style>
<script>
function initTheme() {
const darkThemeSelected =
localStorage.getItem('darkSwitch') !== null &&
localStorage.getItem('darkSwitch') === 'dark';
darkSwitch.checked = darkThemeSelected;
darkThemeSelected ? document.body.setAttribute('data-theme', 'dark') :
document.body.removeAttribute('data-theme');
}
function resetTheme() {
if (darkSwitch.checked) {
document.body.setAttribute('data-theme', 'dark');
localStorage.setItem('darkSwitch', 'dark');
} else {
document.body.removeAttribute('data-theme');
localStorage.removeItem('darkSwitch');
}
}
</script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col sidebar mb-3">
<h1><i class="fa fa-calendar" aria-hidden="true"></i> Laravel Log Viewer</h1>
<p class="text-muted"><i>by Rap2h</i></p>
<div class="custom-control custom-switch" style="padding-bottom:20px;">
<input type="checkbox" class="custom-control-input" id="darkSwitch">
<label class="custom-control-label" for="darkSwitch" style="margin-top: 6px;">Dark Mode</label>
</div>
<div class="list-group div-scroll">
@foreach($folders as $folder)
<div class="list-group-item">
<?php
\Rap2hpoutre\LaravelLogViewer\LaravelLogViewer::DirectoryTreeStructure( $storage_path, $structure );
?>
</div>
@endforeach
@foreach($files as $file)
<a href="?l={{ \Illuminate\Support\Facades\Crypt::encrypt($file) }}"
class="list-group-item @if ($current_file == $file) llv-active @endif">
{{$file}}
</a>
@endforeach
</div>
</div>
<div class="col-10 table-container">
@if ($logs === null)
<div>
Log file >50M, please download it.
</div>
@else
<table id="table-log" class="table table-striped" data-ordering-index="{{ $standardFormat ? 2 : 0 }}">
<thead>
<tr>
@if ($standardFormat)
<th>Level</th>
<th>Context</th>
<th>Date</th>
@else
<th>Line number</th>
@endif
<th>Content</th>
</tr>
</thead>
<tbody>
@foreach($logs as $key => $log)
<tr data-display="stack{{{$key}}}">
@if ($standardFormat)
<td class="nowrap text-{{{$log['level_class']}}}">
<span class="fa fa-{{{$log['level_img']}}}" aria-hidden="true"></span> {{$log['level']}}
</td>
<td class="text">{{$log['context']}}</td>
@endif
<td class="date">{{{$log['date']}}}</td>
<td class="text">
@if ($log['stack'])
<button type="button"
class="float-right expand btn btn-outline-dark btn-sm mb-2 ml-2"
data-display="stack{{{$key}}}">
<span class="fa fa-search"></span>
</button>
@endif
{{{$log['text']}}}
@if (isset($log['in_file']))
<br/>{{{$log['in_file']}}}
@endif
@if ($log['stack'])
<div class="stack" id="stack{{{$key}}}"
style="display: none; white-space: pre-wrap;">{{{ trim($log['stack']) }}}
</div>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
<div class="p-3">
@if($current_file)
<a href="?dl={{ \Illuminate\Support\Facades\Crypt::encrypt($current_file) }}{{ ($current_folder) ? '&f=' . \Illuminate\Support\Facades\Crypt::encrypt($current_folder) : '' }}">
<span class="fa fa-download"></span> Download file
</a>
-
<a id="clean-log" href="?clean={{ \Illuminate\Support\Facades\Crypt::encrypt($current_file) }}{{ ($current_folder) ? '&f=' . \Illuminate\Support\Facades\Crypt::encrypt($current_folder) : '' }}">
<span class="fa fa-sync"></span> Clean file
</a>
-
<a id="delete-log" href="?del={{ \Illuminate\Support\Facades\Crypt::encrypt($current_file) }}{{ ($current_folder) ? '&f=' . \Illuminate\Support\Facades\Crypt::encrypt($current_folder) : '' }}">
<span class="fa fa-trash"></span> Delete file
</a>
@if(count($files) > 1)
-
<a id="delete-all-log" href="?delall=true{{ ($current_folder) ? '&f=' . \Illuminate\Support\Facades\Crypt::encrypt($current_folder) : '' }}">
<span class="fa fa-trash-alt"></span> Delete all files
</a>
@endif
@endif
</div>
</div>
</div>
</div>
<!-- jQuery for Bootstrap -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<!-- FontAwesome -->
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
<!-- Datatables -->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script>
<script>
// dark mode by https://github.com/coliff/dark-mode-switch
const darkSwitch = document.getElementById('darkSwitch');
// this is here so we can get the body dark mode before the page displays
// otherwise the page will be white for a second...
initTheme();
window.addEventListener('load', () => {
if (darkSwitch) {
initTheme();
darkSwitch.addEventListener('change', () => {
resetTheme();
});
}
});
// end darkmode js
$(document).ready(function () {
$('.table-container tr').on('click', function () {
$('#' + $(this).data('display')).toggle();
});
$('#table-log').DataTable({
"order": [$('#table-log').data('orderingIndex'), 'desc'],
"stateSave": true,
"stateSaveCallback": function (settings, data) {
window.localStorage.setItem("datatable", JSON.stringify(data));
},
"stateLoadCallback": function (settings) {
var data = JSON.parse(window.localStorage.getItem("datatable"));
if (data) data.start = 0;
return data;
}
});
$('#delete-log, #clean-log, #delete-all-log').click(function () {
return confirm('Are you sure?');
});
});
</script>
</body>
</html>
================================================
FILE: tests/LaravelLogViewerTest.php
================================================
<?php
namespace Rap2hpoutre\LaravelLogViewer\Tests;
use Illuminate\Support\Facades\File;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Rap2hpoutre\LaravelLogViewer\LaravelLogViewer;
/**
* Class LaravelLogViewerTest
* @package Rap2hpoutre\LaravelLogViewer
*/
class LaravelLogViewerTest extends OrchestraTestCase
{
public function setUp(): void
{
parent::setUp();
config()->set('app.key', 'XP0aw2Dkrk22p0JoAOzulOl8XkUxlvkO');
// Copy "laravel.log" file to the orchestra package.
if (!file_exists(storage_path('logs/laravel.log'))) {
copy(__DIR__ . '/laravel.log', storage_path('logs/laravel.log'));
}
}
/**
* @throws \Exception
*/
public function testSetFile()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setFile("laravel.log");
$this->assertEquals("laravel.log", $laravel_log_viewer->getFileName());
}
public function testSetFolderWithCorrectPath()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setFolder(basename((__DIR__)));
$this->assertEquals("tests", $laravel_log_viewer->getFolderName());
}
public function testSetFolderWithArrayStoragePath()
{
$path = __DIR__;
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath([$path]);
if(!File::exists("$path/samuel")) File::makeDirectory("$path/samuel");
$laravel_log_viewer->setFolder('samuel');
$this->assertEquals("samuel", $laravel_log_viewer->getFolderName());
}
public function testSetFolderWithDefaultStoragePath()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(storage_path());
$laravel_log_viewer->setFolder('logs');
$this->assertEquals("logs", $laravel_log_viewer->getFolderName());
}
public function testSetStoragePath()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(basename(__DIR__));
$this->assertEquals("tests", $laravel_log_viewer->getStoragePath());
}
public function testPathToLogFile()
{
$laravel_log_viewer = new LaravelLogViewer();
$pathToLogFile = $laravel_log_viewer->pathToLogFile(storage_path(('logs/laravel.log')));
$this->assertEquals($pathToLogFile, storage_path('logs/laravel.log'));
}
public function testPathToLogFileWithArrayStoragePath()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath([storage_path()]);
$pathToLogFile = $laravel_log_viewer->pathToLogFile('laravel.log');
$this->assertEquals($pathToLogFile, 'laravel.log');
}
public function testFailOnBadPathToLogFile()
{
$this->expectException(\Exception::class);
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(storage_path());
$laravel_log_viewer->setFolder('logs');
$laravel_log_viewer->pathToLogFile('newlogs/nolaravel.txt');
}
public function testAll()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(__DIR__);
$laravel_log_viewer->pathToLogFile(storage_path('logs/laravel.log'));
$data = $laravel_log_viewer->all();
$this->assertEquals('local', $data[0]['context']);
$this->assertEquals('error', $data[0]['level']);
$this->assertEquals('danger', $data[0]['level_class']);
$this->assertEquals('exclamation-triangle', $data[0]['level_img']);
$this->assertEquals('2018-09-05 20:20:51', $data[0]['date']);
}
public function testAllWithEmptyFileName()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(__DIR__);
$data = $laravel_log_viewer->all();
$this->assertEquals('local', $data[0]['context']);
$this->assertEquals('error', $data[0]['level']);
$this->assertEquals('danger', $data[0]['level_class']);
$this->assertEquals('exclamation-triangle', $data[0]['level_img']);
$this->assertEquals('2018-09-05 20:20:51', $data[0]['date']);
}
public function testFolderFiles()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(__DIR__);
$data = $laravel_log_viewer->foldersAndFiles();
$this->assertIsArray($data);
$this->assertIsArray($data);
$this->assertNotEmpty($data);
$this->assertStringContainsString('tests', $data[count(explode($data[0], '/')) - 1]);
}
public function testGetFolderFiles()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(__DIR__);
$data = $laravel_log_viewer->getFolderFiles();
$this->assertIsArray($data);
$this->assertNotEmpty($data, "Folder files is null");
}
public function testGetFiles()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(storage_path());
$data = $laravel_log_viewer->getFiles();
$this->assertIsArray($data);
$this->assertNotEmpty($data, "Folder files is null");
}
public function testGetFolders()
{
$laravel_log_viewer = new LaravelLogViewer();
$laravel_log_viewer->setStoragePath(storage_path());
$data = $laravel_log_viewer->getFolders();
$this->assertIsArray($data);
$this->assertNotEmpty($data, "files is null");
}
public function testDirectoryStructure()
{
$log_viewer = new LaravelLogViewer();
ob_start();
$log_viewer->directoryTreeStructure(storage_path('logs'), $log_viewer->foldersAndFiles());
$data = ob_get_clean();
$this->assertIsString($data);
$this->assertNotEmpty($data);
}
}
================================================
FILE: tests/laravel.log
================================================
[2018-09-05 20:20:51] local.ERROR: The "--versio" option does not exist. {"exception":"[object] (Symfony\\Component\\Console\\Exception\\RuntimeException(code: 0): The \"--versio\" option does not exist. at /x/y/z/vendor/symfony/console/Input/ArgvInput.php:217)
[stacktrace]
#0 /x/y/z/vendor/symfony/console/Input/ArgvInput.php(153): Symfony\\Component\\Console\\Input\\ArgvInput->addLongOption('versio', NULL)
#1 /x/y/z/vendor/symfony/console/Input/ArgvInput.php(82): Symfony\\Component\\Console\\Input\\ArgvInput->parseLongOption('--versio')
#2 /x/y/z/vendor/symfony/console/Input/Input.php(55): Symfony\\Component\\Console\\Input\\ArgvInput->parse()
#3 /x/y/z/vendor/symfony/console/Command/Command.php(210): Symfony\\Component\\Console\\Input\\Input->bind(Object(Symfony\\Component\\Console\\Input\\InputDefinition))
#4 /x/y/z/vendor/symfony/console/Application.php(886): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#5 /x/y/z/vendor/symfony/console/Application.php(262): Symfony\\Component\\Console\\Application->doRunCommand(Object(Symfony\\Component\\Console\\Command\\ListCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#6 /x/y/z/vendor/symfony/console/Application.php(145): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#7 /x/y/z/vendor/laravel/framework/src/Illuminate/Console/Application.php(89): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#8 /x/y/z/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#9 /x/y/z/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#10 {main}
"}
gitextract_pf84q1ng/
├── .github/
│ └── workflows/
│ └── run-tests.yml
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── phpunit.xml
├── src/
│ ├── Rap2hpoutre/
│ │ └── LaravelLogViewer/
│ │ ├── LaravelLogViewer.php
│ │ ├── LaravelLogViewerServiceProvider.php
│ │ ├── Level.php
│ │ └── Pattern.php
│ ├── config/
│ │ └── logviewer.php
│ ├── controllers/
│ │ └── LogViewerController.php
│ └── views/
│ └── log.blade.php
└── tests/
├── LaravelLogViewerTest.php
└── laravel.log
SYMBOL INDEX (52 symbols across 6 files)
FILE: src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
class LaravelLogViewer (line 5) | class LaravelLogViewer
method __construct (line 40) | public function __construct()
method setFolder (line 51) | public function setFolder($folder)
method setFile (line 81) | public function setFile($file)
method pathToLogFile (line 95) | public function pathToLogFile($file)
method getFolderName (line 127) | public function getFolderName()
method getFileName (line 135) | public function getFileName()
method all (line 143) | public function all()
method foldersAndFiles (line 240) | public function foldersAndFiles($path = null)
method getFolders (line 264) | public function getFolders($folder = '')
method getFolderFiles (line 282) | public function getFolderFiles($basename = false)
method getFiles (line 292) | public function getFiles($basename = false, $folder = '')
method getStoragePath (line 316) | public function getStoragePath()
method setStoragePath (line 326) | public function setStoragePath($path)
method directoryTreeStructure (line 331) | public static function directoryTreeStructure($storage_path, array $ar...
FILE: src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php
class LaravelLogViewerServiceProvider (line 7) | class LaravelLogViewerServiceProvider extends ServiceProvider
method boot (line 14) | public function boot()
method register (line 39) | public function register()
method config_path (line 50) | private function config_path($path = '')
FILE: src/Rap2hpoutre/LaravelLogViewer/Level.php
class Level (line 9) | class Level
method all (line 46) | public function all()
method img (line 55) | public function img($level)
method cssClass (line 64) | public function cssClass($level)
FILE: src/Rap2hpoutre/LaravelLogViewer/Pattern.php
class Pattern (line 5) | class Pattern
method all (line 22) | public function all()
method getPattern (line 32) | public function getPattern($pattern, $position = null)
FILE: src/controllers/LogViewerController.php
class BaseController (line 8) | class BaseController extends \Illuminate\Routing\Controller {}
class BaseController (line 10) | class BaseController extends \Laravel\Lumen\Routing\Controller {}
class LogViewerController (line 17) | class LogViewerController extends BaseController
method __construct (line 37) | public function __construct()
method index (line 47) | public function index()
method earlyReturn (line 95) | private function earlyReturn()
method pathFromInput (line 126) | private function pathFromInput($input_string)
method redirect (line 135) | private function redirect($to)
method download (line 148) | private function download($data)
FILE: tests/LaravelLogViewerTest.php
class LaravelLogViewerTest (line 13) | class LaravelLogViewerTest extends OrchestraTestCase
method setUp (line 16) | public function setUp(): void
method testSetFile (line 29) | public function testSetFile()
method testSetFolderWithCorrectPath (line 39) | public function testSetFolderWithCorrectPath()
method testSetFolderWithArrayStoragePath (line 48) | public function testSetFolderWithArrayStoragePath()
method testSetFolderWithDefaultStoragePath (line 61) | public function testSetFolderWithDefaultStoragePath()
method testSetStoragePath (line 73) | public function testSetStoragePath()
method testPathToLogFile (line 82) | public function testPathToLogFile()
method testPathToLogFileWithArrayStoragePath (line 91) | public function testPathToLogFileWithArrayStoragePath()
method testFailOnBadPathToLogFile (line 101) | public function testFailOnBadPathToLogFile()
method testAll (line 112) | public function testAll()
method testAllWithEmptyFileName (line 125) | public function testAllWithEmptyFileName()
method testFolderFiles (line 138) | public function testFolderFiles()
method testGetFolderFiles (line 151) | public function testGetFolderFiles()
method testGetFiles (line 161) | public function testGetFiles()
method testGetFolders (line 171) | public function testGetFolders()
method testDirectoryStructure (line 181) | public function testDirectoryStructure()
Condensed preview — 15 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (48K chars).
[
{
"path": ".github/workflows/run-tests.yml",
"chars": 2398,
"preview": "name: Tests\n\non:\n push:\n pull_request:\n\njobs:\n tests:\n strategy:\n fail-fast: true\n matrix:\n php: "
},
{
"path": ".gitignore",
"chars": 58,
"preview": "/vendor\ncomposer.lock\n/.idea\n/build\n.phpunit.result.cache\n"
},
{
"path": "LICENSE",
"chars": 1087,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2014-present rap2hpoutre\n\nPermission is hereby granted, free of charge, to any pers"
},
{
"path": "README.md",
"chars": 2911,
"preview": "Laravel log viewer\n==================\n\n[. The extraction includes 15 files (43.6 KB), approximately 12.2k tokens, and a symbol index with 52 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.