Reputation: 417
How do laravel print out some string on console when running php artisan serve?
I tried Log::info
but it isn't working.
Upvotes: 17
Views: 66073
Reputation: 38662
Try with
error_log('message here.');
If You ant add LOG
Log::info('message');
If LOG with an array
Log::info(json_encode($array));
Import
Illuminate\Support\Facades\Log;
You can use dump()
as well. If you use this you have to use dd()
or die
after this.
Apart from all this you can use dd()
laravel in-built output mechanism.
Upvotes: 21
Reputation: 6751
It's very simple.
You can call it from anywhere in APP.
$out = new \Symfony\Component\Console\Output\ConsoleOutput();
$out->writeln("Hello from Terminal");
Upvotes: 30
Reputation: 2910
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
Upvotes: 16
Reputation: 28554
You've to config where laravel to store the logs. Default Log::info()
put the log in the log file not the console. you can use tail -f logpath
to see the log.
Upvotes: 2