ThinkPHP debugging mode and Logging Overview _ php instance

Source: Internet
Author: User
This article mainly introduces the ThinkPHP debugging mode and logging usage. For more information about how to use ThinkPHP debugging mode and logging, see the following section, this function plays an important role in ThinkPHP project development. it is necessary to understand and master it. The specific method is as follows:

1. you can set it in config. php, which is disabled by default.

The method for enabling is as follows:

'APP_DEBUG'  => true

Open the \ ThinkPHP \ Common \ debug. php file to view the default debug settings as follows:

Return array ('log _ record' => true, // perform log record 'log _ RECORD_LEVEL '=> array ('error', 'Alert', 'crit ', 'err', 'warn', 'notic', 'info', 'debug', 'SQL '), // The log level that can be recorded: 'DB _ FIELDS_CACHE '=> false, // The database field caches 'show _ RUN_TIME' => true, // Display 'show _ adv_time' => true, // display the detailed running time 'show _ DB_TIMES '=> true, // display the number of database queries and writes 'show _ CACHE_TIMES '=> true, // display the number of cache operations 'show _ USE_MEM' => true, // display the memory overhead 'show _ PAGE_TRACE '=> true, // display the page Trace information. the Trace file definition and Action operation value 'app _ FILE_CASE' => true, // check whether the file's case sensitivity is valid for Windows );

Note: The DB_FIELDS_CACHE database field cache is disabled by default. if it is enabled, the file cache will be generated in the Runtime \ Data folder and the new field is added after the table is modified, this cache cannot record your operations. you need to manually delete the table once before modification is successful.

After 'app _ debug' => true, the following DEBUG prompt appears when you access the page:

If you only want to display some prompts, such as running time and memory overhead,

You can set it in config. php, for example:

// 'App _ debug' => true, // The DEBUG mode switch 'show _ RUN_TIME '=> true, // The running time is displayed as 'show _ adv_time' => true, // display the detailed running time 'show _ DB_TIMES '=> true, // display the database operation times 'show _ CACHE_TIMES' => true, // display cache operation count 'show _ USE_MEM '=> true, // display memory overhead

The prompt information is as follows:

2. Custom page Trace information: ThinkPHP \ Tpl \ PageTrace. tpl. php

Custom Method 1: Add a trace. php file to the directory of config. php at the same level. the code is as follows:

<? Php return array {'current server information' =>$ _ SERVER ['remote _ ADDR '] ,};?>

Custom Method 2: Add the following in the Action method:

$ This-> trace ('debug test', '123 ');

3. output debugging method:

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

4. model debugging: displays SQL statements.

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

5. logging ThinkPHP \ Lib \ Think \ Core \ Log. class. php

Set in config. php

'Log _ RECORD '=> true, // enable the log record 'log _ RECORD_LEVEL' => array ('error', 'Alert ', 'error '),

I hope this method will be helpful to you.

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.