Skip to content

Instantly share code, notes, and snippets.

@alexandru-gaidei
Last active April 9, 2020 12:35
Show Gist options
  • Save alexandru-gaidei/cce9a04414a7b007c72144ad71d3f786 to your computer and use it in GitHub Desktop.
Save alexandru-gaidei/cce9a04414a7b007c72144ad71d3f786 to your computer and use it in GitHub Desktop.
Laravel public logs. Place this file in the public directory.
<?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