Yii framework is used to record logs to custom files.
This article describes how to record logs to custom files in the Yii framework. We will share this with you for your reference. The details are as follows:
By default,Yii::log($msg, $level, $category)Logs are recorded in the runtime/application. log file.
The log format is as follows:
[Time]-[level]-[category]-[content]
2013/05/03 17:33:08 [error] [application] test
But sometimes some specific logs need to be put into a specific file, such as transaction failure logs, which need to be separately recorded from other logs.
You can configure different CLogRouter in Yii.
You need to first understand the Log Mechanism of Yii. The log function of Yii consists of CLogger and CLogRouter,
CLogger Records log data in the memory, while CLogRouter determines how to process the log data, such as logging to a file or database, or sending emails.
CFileLogRoute is used to process log data in the form of files. Naturally, you can configure different CFileLogRoute to record logs to different log files.
The specific configuration is as follows:
'log' => array( 'class' => 'CLogRouter', 'routes' => array( array( 'class' => 'CFileLogRoute', 'levels' => 'error, warning', ), array( 'class' => 'CFileLogRoute', 'levels' => 'error, warning', 'categories'=> 'orders.*', 'logFile'=> 'orders.log', ),
Add the following code to record order errors:
Yii::log('your message', 'error', 'orders');