I have a question about logs in Yii2. I want to
1.) Access log file (both basic/advanced application)
2.) Parse them using by using regular expressions (separate each part of the log, i partly know, how to do it)
3.) Display them by using widget (in widget i want to specify, what i want 2 show )
Right now, i am struggling, which method to use, when i want to handle those logs. I know they are in : app\frontend|backend|console\runtime\logs\app.log
, but since i am still Yii2 newbie, i don`t really know, how to perform actions like that. Every answer will be appreciated ! Thank you
You can have logs where ever you want with yii2.
You can define your own logs in the config file depending of the application setup you are using.
http://www.yiiframework.com/doc-2.0/yii-log-target.html
Check the config file under the web section and you will see something like that:
// Logging
'log' => [
'targets' => [
// writes to php-fpm output stream
[
'class' => 'codemix\streamlog\Target',
'url' => 'php://stdout',
'levels' => ['info', 'trace'],
'logVars' => [],
'enabled' => YII_DEBUG,
],
You can add new ragets like that:
[
'class' => 'yii\log\FileTarget',
'levels' => ['info', 'trace', 'error', 'warning'],
'categories' => ['mycategory'],
'logVars' => [],
'logFile' => '@runtime/logs/myfolder/myfile.log',
],
To add lines to this logs you will use something like that:
\Yii::info("hi there", 'mycategory');
About how to get this path within your code it is as simple as creating an alias in your config file:
http://www.yiiframework.com/doc-2.0/guide-concept-aliases.html
Yii::setAlias('@runtime', dirname(__DIR__) . '/../../runtime/logs/myfolder');
The rest it is mainly php functions like read the file
http://www.w3schools.com/php/php_file_open.asp
then search about models, passing data from the controller to the view, etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With