我该怎么在Laravel 控制器中输出到控制台?

17 浏览
0 Comments

我该怎么在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日
0
0 Comments

这个问题涉及使用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-.log(Laravel 5.0)。监视日志- Linux/OS X:tail -f /laravel/storage/logs/laravel-.log

0
0 Comments

Aha!

这可以通过以下的PHP函数完成:

error_log('Some message here.');

在这里找到了答案:在PHP内置的Web服务器中打印内容

0