So I have a Laravel controller:
class YeahMyController extends BaseController {
public function getSomething() {
Console::info('mymessage'); // <-- what do I put here?
return 'yeahoutputthistotheresponse';
}
}
Currently, I'm running the application using artisan (which runs PHP's built-in development web server under the hood):
php artisan serve
I would like to log console messages to the STDOUT
pipe for the artisan process.
For better explain Dave Morrissey's answer I have made these steps for wrap with Console Output class in a laravel facade.
1) Create a Facade in your prefer folder (in my case app\Facades):
2) Register a new Service Provider in app\Providers as follow:
}
3) Add all this stuffs in config\app.php file, registering the provider and alias.
That's it, now in any place of your Laravel application, just call your method in this way:
Hope this help you.
I use this for Lumen, pretty sure it will work with Laravel too
You can use echo and prefix "\033", simple:
And change color text:
I wanted my logging information to be sent to stdout because it's easy to tell Amazon's Container service (ECS) to collect stdout and send it to CloudWatch Logs. So to get this working, I added a new stdout entry to my
config/logging.php
file like so:Then I simply added 'stdout' as one of the channels in the stack log channel:
This way, I still get logs in a file for local development (or even on the instance if you can access it), but more importantly they get sent to the stdout which is saved in CloudWatch Logs.
If you want the fancy command IO from Laravel (like styling, asking and table) then I created this class below
Instructions
I have not fully verified everywhere that it is THE cleanest solution etc, but it works nice (but I only tested it from within a unit test case, under Laravel 5.5).
So most probably you can use it however you like:
Or course you can also wrap in your own facade, or some static singleton etc, or anyway you wish.
The class itself
The question relates to serving via artisan and so Jrop's answer is ideal in that case. I.e,
error_log
logging to the apache log.However, if your serving via a standard web server then simply use the Laravel specific logging functions:
With current versions of laravel like this for info:
This logs to Laravel's log file located at
/laravel/storage/logs/laravel-<date>.log
(laravel 5.0). Monitor the log - linux/osx:tail -f /laravel/storage/logs/laravel-<date>.log