This article mainly introduced the YII framework to implement the logging to the custom file method, combined with the case form analysis of YII framework logging principle and custom log records related configuration and implementation skills, the need for friends can refer to the next
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 ');