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

Laravel/Lumen debugging sharp weapon

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

First, the effect picture

Second, function points:

1. Route for the current request

two。 Parameters of the current request

3. The SQL that the current request runs, and the running time of the SQL.

The above three points contain the basic modal information that we must have in the local environment development process.

Third, to achieve:

1. Configuration of the development and running environment

1.1 turn on the .env file add switch. It is recommended that the development environment is set to true, and the production environment is set to falseAPP_DEBUG=true1.2 to set LOG level APP_LOG_LEVEL=debug1.3 to increase print sql switch configuration to open any configuration file of the config directory. Here, I will prevent the configuration to database.php 'sql_debug' = > env (' APP_DEBUG').

two。 Implement print request routing and parameters

Open the App\ Http\ Controllers\ Controller.php file to add construction methods: public function _ _ construct (Request $request) {if (env ('APP_DEBUG')) {\ Log::debug ("\ n\ n");\ Log::debug (' request routing:'. $request- > url (); $requestParameters = $request- > all (); if (! empty ($requestParameters)) {\ Log::debug ('request parameters:'. Var_export ($requestParameters, true);} else {\ Log::debug ('request parameter: none');}

3. Implement the SQL statement for printing and running

Open the App\ Providers\ AppServiceProvider;boot method to add DB listening public function boot () {/ / sql debug $sql_debug = config ('database.sql_debug') / notice here to get the switch configuration if ($sql_debug) {DB::listen (function ($sql) {foreach ($sql- > bindings as $I = > $binding) {if ($binding instanceof\ DateTime) {$sql- > bindings [$I] = $binding- > format ('\ 'Y-m-d H:i:s\') } else {if (is_string ($binding)) {$sql- > bindings [$] = "'$binding'";} $query = str_replace (array ('%','?), array ('%','% s'), $sql- > sql) $query = vsprintf ($query, $sql- > bindings);\ Log::debug ('run SQL:'. $query);\ Log::debug ('time to run:'. $sql- > time. ' Ms');})

IV. Verify and use

The terminal goes to the project root directory and runs the log tracking command

Tail-f. / storage/logs/laravel.log

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

Internet Technology

Wechat

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

12
Report