thinkphp Debug mode and Logging Overview _php instance

Source: Internet
Author: User

This paper describes the usage of thinkphp debug mode and logging, which plays a very important role in the process of thinkphp project development, and it is necessary to understand and master it. The specific methods are as follows:

1, can be set in the config.php, the default is off state.

The opening method is as follows:

' App_debug '  => True

Open the \thinkphp\common\debug.php file to see the default settings for debug as follows:

Return Array (
  ' Log_record ' =>true,//log record
  ' Log_record_level '    =>  Array (' Emerg ', ' ALERT ', ' Crit ', ' ERR ', ' WARN ', ' notic ', ' INFO ', ' DEBUG ', ' SQL ',//Allow logging Level
  ' Db_fields_cache ' => false,//database field cache
  ' Show_run_time ' =>true,//     run time display
  ' Show_adv_time ' =>true,     //Show detailed run time
  ' show_db_times ' = >true,     //Display database query and write Count
  ' show_cache_times ' =>true,    //Show cache Operations
  ' Show_use_mem ' =>true,      //Display memory overhead
  ' Show_page_trace ' =>true,    //Show page trace information assigned by trace file definition and action Operation
  ' app_file_case ' = >  true,//check that file capitalization is valid for Windows platforms
);

Note: The Db_fields_cache database field cache is turned off by default, and if it is turned on, the file cache is generated under the Runtime\data folder, and after the table is modified, such as the newly added field, this cache cannot record your operation and requires us to delete it manually. Changes to the table will not succeed.

After the ' App_debug ' => true, the access page appears with the following DEBUG prompt:

If you want to display only a portion of the hint information, such as elapsed time, memory overhead, etc.,

You can make the appropriate settings in config.php, such as:

' App_debug '  => true,//debug mode switch
' show_run_time ' => true,//Run time display
' Show_adv_time ' => true,// Show detailed elapsed time
' Show_db_times ' => true,//Show Database Operations
' show_cache_times ' =>true,//Show cache operations
' Show_use_ MEM ' => true,//display memory overhead

The following figure is indicated:

2, the page trace information customization: \thinkphp\tpl\pagetrace.tpl.php

Custom method One: Add a trace.php file to the config.php's sibling directory with the following code:

<?php return
 array{
  ' current SERVER information ' =>$_server[' REMOTE_ADDR '],
 };
? >

Custom method Two: Add in the action method:

$this->trace (' Debug Test ', ' 5211314 ');

3, Output Debugging method:

 Halt (' aaaaaaa ');//output AAAAAA and interrupt program execution

4. Model debugging: Displaying SQL statements

 $User =new Model (' User ');
 $User->find (1);
 echo $User->getlastsql ()//output the last SQL statement executed

5, log record \thinkphp\lib\think\core\log.class.php

Set in config.php

 ' Log_record ' =>true,//opened the log
 ' Log_record_level ' =>array (' Emerg ', ' ALERT ', ' ERROR '),

I hope the method described in this article will be helpful to everyone.

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.