Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

ThinkPHP debug mode and usage of logging

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "ThinkPHP debugging mode and the use of logging". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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

1. You can set it in config.php. It is disabled by default.

The opening method is as follows:

'APP_DEBUG' = > true

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

Return array ('LOG_RECORD'= > true, / / logging' LOG_RECORD_LEVEL' = > array ('EMERG','ALERT','CRIT','ERR','WARN','NOTIC','INFO','DEBUG','SQL'), / / allowed logging level' DB_FIELDS_CACHE'= > false, / / Database field cache 'SHOW_RUN_TIME'= > true / / run time display 'SHOW_ADV_TIME'= > true, / / display detailed run time' SHOW_DB_TIMES'= > true, / / display database query and write times' SHOW_CACHE_TIMES'= > true, / / show cache operations' SHOW_USE_MEM'= > true, / / show memory cost 'SHOW_PAGE_TRACE'= > true / / display page Trace information is defined by Trace file and assigned by Action operation 'APP_FILE_CASE' = > true, / / whether to check whether the case of the file is valid for Windows platform)

Note: DB_FIELDS_CACHE database field cache is disabled by default. If it is enabled, the file cache will be generated under the Runtime\ Data folder. After modifying the table, if a new field is added, the cache cannot record your actions. We need to delete it manually before the modification of the table will be successful.

After setting 'APP_DEBUG' = > true, the DEBUG prompt in the following figure appears on the visiting page:

If you only want to display some of the prompts, such as run time, memory overhead, etc.

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

/ / 'APP_DEBUG' = > true, / / Debug mode switch' SHOW_RUN_TIME' = > true, / / Runtime 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 prompt message is as follows:

2. Customize the Trace information of the page:\ ThinkPHP\ Tpl\ PageTrace.tpl.php

Custom method 1: add a trace.php file to the sibling directory of config.php with the following code:

Custom method 2: add to the Action method:

$this- > trace ('debug test', '5211314')

3. Output debugging method:

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

4. Model debugging: display 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,// enables logging 'LOG_RECORD_LEVEL'= > array (' EMERG','ALERT','ERROR'). That's all for ThinkPHP debugging mode and how to use logging. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report