How to print messages on console in Laravel?
Laravel 5.6 simplified this because you now have a logging.php
config file you could leverage.
The key thing to know is that you want to output to stdout
and php has a stream wrapper built-in called php://stdout
. Given that, you could add channel for that wrapper. You would add the stdout "channel" to your channels that you will be logging to.
Here's how the config will basically look:
<?php return [ 'default' => env('LOG_CHANNEL', 'stack'), 'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => ['single','stdout'], ], 'single' => [ 'driver' => 'single', 'path' => storage_path('logs/laravel.log'), 'level' => 'debug', ], 'stdout' => [ 'driver' => 'monolog', 'handler' => StreamHandler::class, 'with' => [ 'stream' => 'php://stdout', ], ],];
I have more information here - Laravel 5.6 - Write to the Console