'print request body in the console in Yii 2
in Yii2 rest API, I need to print the request body in the Visual Studio code's terminal. Is there a way to do that? I tried varduming and echoing but couldn't achieve the result.
Solution 1:[1]
In Yii2 you can create debug message using
\Yii::trace("this is my debug message");
which is added to ./runtime/log/application.log
On the command line (e.g. in Visual Code) to see this debug messages, do this:
$ cd runtime/log
$ tail -f application.log
You can stop the tail
-command using ^C.
If this is too much output, you can refine debugging messag output in ./config/web.php
:
$config = [
...
'components' => [
...
'log' => [
...
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning', 'trace'],
'logVars' => [], // no $SERVER vars
],
],
],
];
return $config;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | WeSee |