Search code examples
phplaravelloggingconsole

How do I write to the console from a Laravel Controller?


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.


Solution

  • Aha!

    This can be done with the following PHP function:

    error_log('Some message here.');
    

    Found the answer here: Print something in PHP built-in web server