spatie/nova-tail-tool
Laravel Nova tool that tails and displays your application log inside Nova. Adds an “Application log” menu item and streams new lines as they’re written, making it easy to monitor errors and activity without leaving the admin panel.
Installation
composer require spatie/nova-tail-tool
Publish the config file (if needed):
php artisan vendor:publish --provider="Spatie\NovaTailTool\NovaTailToolServiceProvider"
Register the Tool
Add the tool to your Nova tools() method in app/Providers/NovaServiceProvider.php:
public function tools()
{
return [
// ... other tools
new \Spatie\NovaTailTool\NovaTailTool,
];
}
First Use Case
storage/logs/laravel.log).error, info) or search for specific terms.Real-Time Log Monitoring
Log Filtering & Search
error, warning) via dropdown.authentication errors during a login bug.Multi-Environment Logs
config/nova-tail-tool.php:
'log_files' => [
'local' => storage_path('logs/laravel.log'),
'production' => '/var/www/storage/logs/laravel.log',
],
Integration with Nova Actions
public function handle()
{
NovaTailTool::tail(); // Redirects to the tool with pre-configured settings
}
Customizing Log Display
NovaTailTool::macro('formatLog', function ($log) {
return preg_replace('/"user_id": (\d+)/', '<span class="text-yellow-500">"user_id": $1</span>', $log);
});
Permission Issues
storage/logs/).chmod -R 755 storage/logs/
ln -s /var/www/storage/logs /path/to/writable/logs
High-Volume Logs
logrotate to split logs or configure max_lines in config:
'max_lines' => 1000, // Limits displayed logs
Environment-Specific Paths
storage_path('logs/laravel.log')) break in shared hosting.env('LOG_FILE') or publish the config to customize per environment.Real-Time vs. Polling
Logs Not Loading?
Check the browser’s Network tab for failed requests to /nova/v1/nova-tail-tool/logs.
config/nova-tail-tool.php.file_exists() in Tinker).Stale Logs? Clear cached views:
php artisan view:clear
Or restart Nova’s queue worker if using background processing.
Custom Log Sources Override the default log source (e.g., database logs):
NovaTailTool::macro('getLogSource', function () {
return new CustomLogSource();
});
Add Context to Logs Enhance logs with clickable links (e.g., user IDs):
NovaTailTool::macro('formatLog', function ($log) {
return str_replace(
'user_id=123',
'<a href="/nova/users/123" target="_blank">user_id=123</a>',
$log
);
});
Log Level Colors
Customize CSS for log levels in resources/css/nova-tail-tool.css:
.log-error { color: #ff0000; }
.log-info { color: #00aa00; }
API Access Fetch logs programmatically via Nova’s API:
$logs = Http::withHeaders([
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $novaToken,
])->get('nova/v1/nova-tail-tool/logs');
How can I help you explore Laravel packages today?