Yii framework is used to record logs to custom files.

Source: Internet
Author: User

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');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.