Last active
April 9, 2020 12:35
-
-
Save alexandru-gaidei/cce9a04414a7b007c72144ad71d3f786 to your computer and use it in GitHub Desktop.
Laravel public logs. Place this file in the public directory.
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
<?php | |
require __DIR__.'/../vendor/autoload.php'; | |
$app = require_once __DIR__.'/../bootstrap/app.php'; | |
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); | |
$kernel->handle(Illuminate\Http\Request::capture()); | |
if (! config('app.debug')) { | |
abort(404); | |
} | |
$path = __DIR__.'/logs'; | |
if (! is_dir($path)) { | |
echo 'Logs dir not found. Please make symlink first: <pre>cd webroot/public && ln -s ../storage/logs/ ./logs</pre>'; | |
exit; | |
} | |
if ($file = request()->get('file')) { | |
$content = file_get_contents("$path/$file"); | |
echo nl2br($content); | |
exit; | |
} | |
$files = scandir($path); | |
$exclude_files = ['.', '..', '.gitignore']; | |
echo '<ul>'; | |
foreach($files as $file) { | |
if (in_array($file, $exclude_files)) continue; | |
echo "<li><a href='/logs.php?file=$file'>$file</a></li>"; | |
} | |
echo '</ul>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment