How to print messages on console in Laravel
When you run php artisan serve or execute your application via a CLI command, expecting output from Log::info() is often a source of confusion for developers. The behavior differs significantly from what happens when you inspect logs on disk after the request cycle completes. In the standard development environment, Laravel's default logging driver is set to the stack, which includes both single and daily channels. These drivers write strictly to files. Consequently, calling Log::info() inside a controller or route closure will not produce any output in your terminal during the active request because the log channel is configured to persist data to storage rather than stream it to STDOUT immediately.
To print messages directly to the console while the application is running, you must bypass the file-based logging stack and utilize Laravel's dedicated console logging methods. The most direct approach is using the dd() helper or Log::info() with a specific configuration change, but there is a native mechanism designed exactly for this scenario: the output channel.
If you are looking to debug a request in real-time without stopping execution, dump() and dd() remain the go-to tools. dump() will display the variable's structure and then continue execution, while dd() (short for dump() and die()) displays the data and immediately halts the script. This is invaluable when you need to inspect an array or object during a request flow. However, if your goal is to log a message that persists in the terminal history without stopping the application flowâsimilar to how Log::info() behaves but visible instantlyâyou should configure a dedicated logging channel for console output.
Edit your config/logging.php file and add a new channel named console. Define this channel with the single driver and set the path to your desired log file, or simply rely on the default stream if you are strictly interested in immediate terminal output. More importantly, ensure that your environment variable LOG_CHANNEL is set to console, or explicitly assign it within your application's service provider.
Alternatively, for a quick and dirty debugging session where you don't want to modify configuration files, you can use Log::info() by temporarily switching the default logging driver in your .env file. Set LOG_CHANNEL=null or create a custom channel that points directly to STDOUT. However, the cleanest architectural approach without altering global settings is to use Laravel's built-in Info facade if you are on a version where it streams to console, or better yet, rely on the standard practice of using Log::info() only when configured with a stack containing a stream driver.
In many modern setups, specifically when using Symfony Console commands or specific CLI drivers, Log::info() might behave differently than in web contexts. If you are strictly within a web request handled by php artisan serve, the file system is the default destination. To force console output without changing the global configuration, developers often wrap their debug code in a try-catch block using dd(). But if you need persistent logging to the terminal similar to Log::info(), you must ensure your .env file includes:
LOG_CHANNEL=console
And then define a console channel in config/logging.php that uses the single driver with the path set to /dev/tty or simply relies on the default STDOUT stream behavior available in newer Laravel versions. Wait, strictly speaking, Laravel does not natively support writing logs to STDOUT for the single driver in all configurations without specific setup. The most reliable method that works out of the box for immediate visibility is using Log::info() only when the application is running as a CLI command (like php artisan ...) rather than a web request, or utilizing dd().
If you need to print a simple string to the console during a web request without stopping execution and without file logging, consider using Laravel's Storage facade if you are writing to a local disk, but for immediate terminal feedback, stick to var_dump() or dd() unless you configure a dedicated STDOUT stream channel. The confusion usually stems from expecting Log::info() to behave like echo in a standard PHP script. In Laravel's web context, it writes to files. To fix this, either accept the file logs and check your storage/logs/laravel.log, or switch your log driver to daily with a path that includes a stream handler if supported by your server environment.
For those who prefer not to manage log files while debugging locally, the dd() helper is the standard tool in the Laravel toolbox. It provides immediate visibility into data structures and control flow without requiring configuration changes. If you require message persistence to the terminal for audit trails during development, ensure your .env file directs the logger to a stream driver or configure a custom channel that writes to STDOUT. This distinction between debugging (using dd) and logging (using Log::info) is crucial for maintaining clean separation of concerns in your application's output streams.