Print log to terminal running artisan serve

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Print Log to Terminal Running artisan serve: Real-Time Debugging with Laravel

As developers, our primary goal when debugging is visibility. When working with frameworks like Laravel, we rely heavily on the logging system to track application flow and errors. By default, Laravel configures its log channels to write messages to files (like storage/logs/laravel.log), which is excellent for persistence but can slow down real-time debugging when running a development server using php artisan serve.

The challenge you are facing—wanting logs to appear directly in the terminal alongside your running application—is very common during local development. While Laravel's default setup prioritizes file logging, there are several effective ways to redirect output and achieve that real-time terminal feedback.

This post will explore the best strategies for printing log messages directly to your console while running php artisan serve, moving beyond simple file tailing.

Why File Logging is Standard (And When It Fails)

Laravel’s logging mechanism, defined in config/logging.php, is designed for production persistence. Writing everything to a structured file ensures that logs are easily searchable, managed by log rotation policies, and safe from being lost across server restarts. This is a robust practice, especially as you scale your application.

However, during active development using artisan serve, waiting for the file to be written (or using tail -f) introduces latency. We need methods that leverage PHP’s native output streams to achieve immediate feedback.

Strategy 1: Direct Output via echo and Standard Streams

The most straightforward way to get output directly to the terminal is by bypassing the formal logging facade temporarily and using standard PHP output functions (echo, print, or fwrite). This sends data directly to the standard output stream (stdout), which is captured by your terminal.

While not using the official Log facade, this method provides instant debugging visibility:

php
<?php

// Instead of Log::info('Debugging step'), use direct output for immediate feedback
echo "DEBUG: Starting complex operation at " . date('Y-m-d H:i:s') . "\n";

if (some_condition_is_true) {
    echo "INFO: Condition met. Proceeding to next step.\n";
} else {
    echo "WARNING: Condition failed. Rolling back operation.\n";
}

// This output will appear immediately in your terminal running artisan serve.

Developer Insight: This technique is excellent for quick checks, testing conditional logic, or printing temporary state information during a specific request lifecycle within your controller or service layer.

Strategy 2: Custom Log Drivers for Terminal Output (Advanced)

For scenarios where you want the entire logging system to respect terminal output, you need to customize how logs are written. This involves creating a custom Monolog handler that targets php://stdout instead of a file stream.

This is a more advanced technique, often employed in complex systems or when building custom log aggregators. You would configure your config/logging.php to use this custom driver for development environments:

php
// Example conceptual configuration snippet (requires custom Monolog setup)
'channels' => [
    'terminal' => [
        'driver' => 'monolog',
        'handler' => [
            'type' => 'stream',
            'stream' => 'php://stdout', // Directs output to the terminal stream
        ],
        'level' => 'debug',
    ],
],

While implementing a full custom driver is complex, understanding this concept ties directly into how Laravel manages its services. For deeper architectural insights on service management and configuration within the framework, reviewing documentation like that provided by laravelcompany.com is highly recommended.

Conclusion: Choosing the Right Tool for the Job

For most day-to-day debugging when running artisan serve, Strategy 1 (Direct Output via echo) is the fastest, simplest, and most practical approach. It gives you immediate feedback without requiring complex configuration changes to your logging setup.

Reserve Strategy 2 (Custom Log Drivers) for situations where you need a fully integrated system—perhaps writing specific, high-priority debugging messages directly to the console while keeping all other structured logs safely stored in files. By combining these methods, you gain both real-time visibility and long-term persistence, mastering your application's lifecycle from development through production.