How the Yii framework implements logging to a custom file

Source: Internet
Author: User
Tags yii
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

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.