opcodesio/log-viewer
Fast, beautiful log viewer for Laravel. Browse and manage log files, search and filter entries by level, share links, use dark mode, and preview mails. Supports multiple hosts, Horizon logs, and an API for folders, files, and entries.
Installation:
composer require opcodesio/log-viewer
php artisan log-viewer:publish
This installs the package and publishes assets (Vue.js frontend).
First Access:
Visit {APP_URL}/log-viewer (e.g., http://localhost:8000/log-viewer). No additional configuration is required for basic Laravel log viewing.
First Use Case:
storage/logs/laravel.log for recent errors.SQLSTATE[HY000]).error, warning) via the sidebar.Log Exploration:
Advanced Filtering:
debug, info, warning, error, etc.error AND "timeout").API Integration:
/log-viewer/api/folders, /log-viewer/api/logs).
Example (JavaScript):
fetch('/log-viewer/api/logs?file=laravel.log')
.then(response => response.json())
.then(logs => console.log(logs));
auth:sanctum middleware).Log Management:
/log-viewer?file=laravel.log&line=42 to share specific log entries.Custom Log Formats:
config/log-viewer.php:
'parsers' => [
'custom' => \Opcodes\LogViewer\Parsers\CustomParser::class,
],
Opcodes\LogViewer\Contracts\LogParser to handle non-standard log formats.Multi-Host Environments:
log-viewer to scan logs from remote hosts by adding entries to log-viewer.includes:
includes:
- path: /var/log/myapp
remote: true
host: ssh://user@remote-server
Octane Compatibility:
$app->bind(Opcodes\LogViewer\Services\LogService::class, function ($app) {
return new Opcodes\LogViewer\Services\LogService(
$app->make(Opcodes\LogViewer\Repositories\LogRepository::class)
);
});
Frontend Customization:
config/log-viewer.php:
'frontend' => [
'defaults' => [
'itemsPerPage' => 50,
'darkMode' => true,
],
],
php artisan vendor:publish --tag=log-viewer-assets
Permission Issues:
www-data, nginx) has read access to log directories:
chmod -R 755 storage/logs
chown -R www-data:www-data storage/logs
Missing Logs:
app.log) are not detected.log-viewer.includes:
includes:
- path: storage/logs/app.log
Horizon Logs Not Showing:
log-viewer.includes:
includes:
- path: storage/logs/horizon.log
parser: horizon
API Authentication Failures:
401 Unauthorized.routes/web.php:
Route::middleware(['auth:sanctum'])->group(function () {
Route::prefix('log-viewer/api')->group(base_path('vendor/opcodes/log-viewer/src/Routes/api.php'));
});
Multiline Logs (Nginx/Apache):
includes:
- path: /var/log/nginx/access.log
parser: nginx
multiline: true
Log Parser Debugging:
config/log-viewer.php:
'debug' => true,
storage/logs/laravel.log) for parser errors.Indexing Issues:
php artisan log-viewer:rebuild-index
index_path in config/log-viewer.php to a writable directory.Frontend Assets:
php artisan view:clear
php artisan cache:clear
assets_path in config/log-viewer.php is correct.Custom Log Parsers:
Opcodes\LogViewer\Contracts\LogParser:
namespace App\Parsers;
use Opcodes\LogViewer\Contracts\LogParser;
use Opcodes\LogViewer\Models\LogEntry;
class CustomParser implements LogParser {
public function parse(string $line): ?LogEntry {
// Parse custom log format and return a LogEntry instance
}
}
config/log-viewer.php:
'parsers' => [
'custom' => \App\Parsers\CustomParser::class,
],
API Extensions:
routes/web.php:
Route::prefix('log-viewer/api')->group(function () {
Route::get('/custom-endpoint', [\App\Http\Controllers\LogViewerController::class, 'customMethod']);
});
Opcodes\LogViewer\Services\LogService) for consistency.Event Listeners:
namespace App\Listeners;
use Opcodes\LogViewer\Events\LogEntryCreated;
class LogEntryListener {
public function handle(LogEntryCreated $event) {
// Custom logic (e.g., notify Slack)
}
}
EventServiceProvider:
protected $listen = [
LogEntryCreated::class => [
LogEntryListener::class,
],
];
Dark Mode Toggle:
// resources/js/log-viewer/components/App.vue
export default {
data() {
return {
darkMode: false, // Override default
};
},
};
includes Path Handling:
log-viewer.includes are resolved relative to the Laravel root unless prefixed with / (absolute path).includes:
- path: logs/app.log # Relative to Laravel root
- path: /var/log/nginx/error.log
How can I help you explore Laravel packages today?