How does the YII framework implement logging to a custom file? In this paper, the author introduces the method that the Yii framework realizes logging to the custom file, analyzes the principle of the yii frame logging and the related configuration and implementation skills of the custom log record in the instance form, and needs the friend to refer to. We hope to help you.
The example in this paper describes how the Yii framework implements logging to a custom file. Share to everyone for your reference, as follows:
By default, Yii::log($msg, $level, $category)
logs are logged to the Runtime/application.log file
The log format is as follows:
[Time]-[level]-[category]-[content]
2013/05/03 17:33:08 [ERROR] [application] Test
Sometimes, however, you need to put certain logs in a particular file, such as a log of a failed transaction, and separate records from other logs.
In Yii, it can be solved by configuring different clogrouter.
You need to know the logging mechanism of Yii First, Yii's log function has Clogger and clogrouter two parts,
Where Clogger is responsible for logging the log data in memory, and Clogrouter decides how to process the log data, such as logging to a file or database, or sending mail, etc.
The cfilelogroute is used to process log data in the form of files. Naturally, by configuring different Cfilelogroute, logs can be logged to different log files.
The specific configuration is as follows:
' Log ' = = Array ( ' class ' = ' Clogrouter ', ' routes ' = = Array ( ' class ' = ') ' Cfilelogroute ', ' levels ' = ' Error, warning ', ', ' Array ( ' class ' = ' Cfilelogroute ', ' Levels ' + ' ERROR, warning ', ' categories ' = ' orders.* ', ' logFile ' = ' orders.log ',
Add the following code where you need to record an order error:
Yii::log (' Your message ', ' Error ', ' orders ');
Related recommendations:
A detailed description of the attributes (property) in Yii
Yii Related Query detailed
Form form in the YII framework