How to create a log file PHP Yii Framework
Today, We want to share with you How to create a log file PHP Yii Framework.
In this post we will show you php – YII logging for debugging, hear for PHP yii Framework Error handling, Debugging, and Logging we will give you demo and example for implement.
In this post, we will learn about PHP Yii Framework Logging Basics with an example.
PHP Yii Framework – Logging
To log a create error or message, We should call one of the following some Yii Methods
- Yii::error() − Display row a fatal error message.
- Yii::warning() − debug a warning message.
- Yii::info() − create a new a message with some change the information.
- Yii::trace() − Data new row a message to debug how a errro piece of lins of the code runs.
PHP YII framework Logging Location
Where the log file will be stored in PHP YII framework?
We can simple Path find it here easily Protected/runtime/application.log, And We can simple PHP Framework Yii enable the create weblog in protected/config/main.php
Simpl Step To Create a log file PHP Yii Framework
Step 1 − We can simple register multiple file log target as well, such as.
return [ // the PHP Yii "log" component is main loaded during run time 'bootstrap' => ['log'], 'components' => [ 'log' => [ 'targets' => [ [ 'class' => 'yii\log\DbTarget', // 4 Types og the generated logs 'levels' => ['error', 'warning', 'trace', 'info'], ], [ 'class' => 'yii\log\EmailTarget', 'levels' => ['error', 'warning'], 'categories' => ['yii\db\*'], 'message' => [ 'from' => ['[email protected]'], 'to' => ['[email protected]', '[email protected]'], 'subject' => 'Application errors at pakainfo.com', ], ], ], ], ], ];
Step 2 − To PHP Yii Framework customize this date and time format, We need to settings the yii\log\Target::$prefix some property.
[ 'class' => 'yii\log\FileTarget', 'prefix' => function ($message) { $client = Yii::$app->has('client', true) ? Yii::$app->get('client') : 'undefined client'; $clientID = $client ? $client->getId(false) : 'anonym'; return "[$clientID]"; } ]
How to create a logfile in PHP
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Introduction To PHP Yii – Logging.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.