Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Laravel/Lumen debugging sharp weapon

Shulou Source: shulou.com Published: 2022-06-03 04:11:21 10月26日 Update

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

Tags: Run configure parameter environment file route development method information function command suggestion effect effect graph log time root directory directory level terminal Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Microsoft Shulou Technology Linux Shulou Tech Info