我该怎么在Laravel 控制器中输出到控制台?
我该怎么在Laravel 控制器中输出到控制台?
所以我有一个Laravel的控制器:
class YeahMyController extends BaseController { public function getSomething() { Console::info('mymessage'); // <-- what do I put here? return 'yeahoutputthistotheresponse'; } }
目前,我正在使用artisan运行应用程序(这在幕后运行PHP内置的开发Web服务器):
php artisan serve
我想将控制台消息记录到artisan进程的 STDOUT
管道中。
admin 更改状态以发布 2023年5月23日
这个问题涉及使用artisan来服务,因此Jrop的答案是理想的。例如,将error_log
日志记录到Apache日志中。
然而,如果你使用标准的Web服务器,则只需使用Laravel特定的记录函数:
\Log::info('This is some useful information.'); \Log::warning('Something could be going wrong.'); \Log::error('Something is really going wrong.');
或者,在当前版本的Laravel中,可以像这样使用:
info('This is some useful information.');
这将记录到Laravel的日志文件,位于/laravel/storage/logs/laravel-
(Laravel 5.0)。监视日志- Linux/OS X:tail -f /laravel/storage/logs/laravel-
- Laravel 5.0 http://laravel.com/docs/5.0/errors
- Laravel 4.2: http://laravel.com/docs/4.2/errors