How to print messages on console in Laravel? How to print messages on console in Laravel? laravel laravel

How to print messages on console in Laravel?


It's very simple.

You can call it from anywhere in APP.

$out = new \Symfony\Component\Console\Output\ConsoleOutput();$out->writeln("Hello from Terminal");


Try with

error_log('message here.');

Read More


If You ant add LOG

Log::info('message');

If LOG with an array

Log::info(json_encode($array));

Import Illuminate\Support\Facades\Log;


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