laravel 将日志打印到运行 artisan serve 的终端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37510225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Print log to terminal running artisan serve
提问by geckob
I am trying to debug my application and I had few log statements using Log
facade. For now, I run the application using artisan serve
and it will write the log message to the log file and to get a real time log message I run.
我正在尝试调试我的应用程序,并且使用Log
Facade 的日志语句很少。现在,我使用运行应用程序artisan serve
,它将日志消息写入日志文件并获取我运行的实时日志消息。
tail -f laravel.log
Is there any way I can directly print the log message to the same console/terminal that is running php artisan serve
?
有什么办法可以将日志消息直接打印到正在运行的同一个控制台/终端php artisan serve
?
回答by aquasmit
You can do this using following. This works anywhere..
您可以使用以下方法执行此操作。这适用于任何地方..
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$output->writeln("<info>Error message</info>");
This will print the message in terminal / console that is running php artisan serve
这将在正在运行的终端/控制台中打印消息 php artisan serve
回答by IllegalPigeon
tail -f storage/logs/laravel.log & php artisan serve
回答by Steeve Lefort
The standard "error_log" PHP function does what you want.
标准的“error_log”PHP 函数可以满足您的需求。
回答by Mr. B.
Based on @aquasmit answer:
基于@aquasmit 的回答:
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$output->writeln("<info>Info message</info>");
Note the added \
before Symfony
.
注意\
之前添加的Symfony
。