ThinkPHP debugging mode and logging overview, thinkphp Logging
This article describes how to use ThinkPHP debugging mode and logging. 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. Log records \ 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.
Where the thinkphp log file exists
Log records \ ThinkPHP \ Lib \ Think \ Core \ Log. class. php
1. You can set it in config. php, Which is disabled by default. 'App _ debug' => true
Open the \ ThinkPHP \ Common \ debug. php file to view the default debug settings as follows:
Return array (
'Log _ RECORD '=> true, // logs
'Log _ RECORD_LEVEL '=> array ('emerg', 'alert ', 'crit', 'err', 'warn', 'notic', 'info ', 'debug', 'SQL'), // The log level that can be recorded
'Db _ FIELDS_CACHE '=> false, // cache database fields
'Show _ RUN_TIME '=> true, // Run Time Display
'Show _ adv_time' => true, // displays the detailed running time.
'Show _ DB_TIMES '=> true, // displays the number of database queries and writes.
'Show _ CACHE_TIMES '=> true, // displays the number of cache operations
'Show _ USE_MEM '=> true, // Display memory overhead
'Show _ PAGE_TRACE '=> true, // The Trace information of the displayed page is assigned by the Trace file definition and Action operation.
'App _ FILE_CASE '=> true, // check whether the file is case-sensitive for Windows Platforms
);
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, // DEBUG mode switch
'Show _ RUN_TIME '=> true, // Run Time Display
'Show _ adv_time' => true, // displays the detailed running time.
'Show _ DB_TIMES '=> true, // display number ...... remaining full text>
Zhang Haibo [authoritative expert]
THINKPHP call template and debugging mode
Let me tell you the answer!
You can create an IndexAction. class. php file in Admin/Lib/Action,
Display ();
}
}
Create an indexfolder in Admin/tpland create an index.html file in the folder.