소스 검색

feat:增加所有可用命令,以及环境配置

Yin Bin 5 달 전
부모
커밋
e81e730fb6
10개의 변경된 파일114개의 추가작업 그리고 78개의 파일을 삭제
  1. 3 1
      .vscode/extensions.json
  2. 11 5
      .vscode/launch.json
  3. 12 0
      .vscode/settings.json
  4. 6 0
      README.md
  5. 44 0
      app/Providers/QueryLogServiceProvider.php
  6. 2 0
      config/app.php
  7. 5 69
      config/logging.php
  8. 3 1
      script/ansible/bin/deploy
  9. 2 2
      script/ansible/bin/frpc
  10. 26 0
      script/bin/mylog

+ 3 - 1
.vscode/extensions.json

@@ -23,7 +23,9 @@
         "christian-kohler.path-intellisense",
         "mehedidracula.php-namespace-resolver",
         "aaron-bond.better-comments",
-        "naumovs.color-highlight"
+        "naumovs.color-highlight",
+        "openlens.vscode-laravel-log-viewer",
+        "DEVSENSE.phptools-vscode"
     ],
     "unwantedRecommendations": []
 }

+ 11 - 5
.vscode/launch.json

@@ -32,19 +32,25 @@
             "runtimeArgs": [
                 "-dxdebug.mode=debug",
                 "-dxdebug.start_with_request=yes",
+                "-dxdebug.log_level=7",
                 "artisan",
                 "serve",
-                "--host=192.168.110.10",
-                "--port=80"
+                "--host=127.0.0.1",
+                "--port=80",
+                "-v"
             ],
             "program": "",
             "cwd": "${workspaceRoot}",
             "port": 9003,
             "serverReadyAction": {
-                "pattern": "Development Server \\(http://192.168.110.10:80\\) started",
-                "uriFormat": "http://192.168.110.10:80",
+                "pattern": "Development Server \\(http://127.0.0.1:80\\) started",
+                "uriFormat": "http://127.0.0.1:80",
                 "action": "openExternally"
+            },
+            "env": {
+                "APP_DEBUG": "true",
+                "LOG_LEVEL": "debug"
             }
         }
     ]
-}
+}

+ 12 - 0
.vscode/settings.json

@@ -63,4 +63,16 @@
     "database-client.autoSync": true,
     "files.eol": "\n",
     "notebook.lineNumbers": "on",
+    "terminal.integrated.cwd": "${workspaceFolder}",
+    "terminal.integrated.defaultProfile.linux": "zsh",
+    "terminal.integrated.profiles.linux": {
+        "zsh": {
+            "path": "zsh",
+            "icon": "terminal",
+            "args": ["-l"]
+        }
+    },
+    "terminal.integrated.env.linux": {
+        "PATH": "${env:PATH}:${workspaceFolder}/vendor/bin:${workspaceFolder}/script/ansible/bin:${workspaceFolder}/script/bin"
+    }
 }

+ 6 - 0
README.md

@@ -42,3 +42,9 @@ luanch.json中添加:
     "port": 9003
 },
 ```
+
+## 设置linux 允许php以80端口启动
+
+```bash
+sudo setcap 'cap_net_bind_service=+ep' /www/server/php/82/bin/php
+```

+ 44 - 0
app/Providers/QueryLogServiceProvider.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace App\Providers;
+
+use Illuminate\Support\ServiceProvider;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+
+class QueryLogServiceProvider extends ServiceProvider
+{
+    /**
+     * Register services.
+     */
+    public function register(): void
+    {
+        //
+    }
+
+    /**
+     * Bootstrap services.
+     */
+    public function boot(): void
+    {
+        if (config('app.debug')) {
+            DB::listen(function($query) {
+                $sql = $query->sql;
+                $bindings = $query->bindings;
+                $time = $query->time;
+
+                // 格式化SQL语句(替换占位符)
+                foreach ($bindings as $binding) {
+                    $value = is_numeric($binding) ? $binding : "'".$binding."'";
+                    $sql = preg_replace('/\?/', $value, $sql, 1);
+                }
+
+                // 记录SQL日志
+                Log::channel('sql')->debug('SQL', [
+                    'sql' => $sql,
+                    'time' => $time.'ms',
+                ]);
+            });
+        }
+    }
+}

+ 2 - 0
config/app.php

@@ -162,6 +162,8 @@ return [
         // Package Service Providers...
         Knuckles\Scribe\ScribeServiceProvider::class,
 
+        // Application Service Providers...
+        App\Providers\QueryLogServiceProvider::class,
     ],
 
     /*

+ 5 - 69
config/logging.php

@@ -4,57 +4,20 @@ use Monolog\Handler\NullHandler;
 use Monolog\Handler\StreamHandler;
 use Monolog\Handler\SyslogUdpHandler;
 use Monolog\Processor\PsrLogMessageProcessor;
+use Monolog\Formatter\LineFormatter;
 
 return [
-
-    /*
-    |--------------------------------------------------------------------------
-    | Default Log Channel
-    |--------------------------------------------------------------------------
-    |
-    | This option defines the default log channel that is utilized to write
-    | messages to your logs. The value provided here should match one of
-    | the channels present in the list of "channels" configured below.
-    |
-    */
-
     'default' => env('LOG_CHANNEL', 'stack'),
 
-    /*
-    |--------------------------------------------------------------------------
-    | Deprecations Log Channel
-    |--------------------------------------------------------------------------
-    |
-    | This option controls the log channel that should be used to log warnings
-    | regarding deprecated PHP and library features. This allows you to get
-    | your application ready for upcoming major versions of dependencies.
-    |
-    */
-
     'deprecations' => [
         'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
         'trace' => env('LOG_DEPRECATIONS_TRACE', false),
     ],
 
-    /*
-    |--------------------------------------------------------------------------
-    | Log Channels
-    |--------------------------------------------------------------------------
-    |
-    | Here you may configure the log channels for your application. Laravel
-    | utilizes the Monolog PHP logging library, which includes a variety
-    | of powerful log handlers and formatters that you're free to use.
-    |
-    | Available drivers: "single", "daily", "slack", "syslog",
-    |                    "errorlog", "monolog", "custom", "stack"
-    |
-    */
-
     'channels' => [
-
         'stack' => [
             'driver' => 'stack',
-            'channels' => explode(',', env('LOG_STACK', 'single')),
+            'channels' => ['single'],
             'ignore_exceptions' => false,
         ],
 
@@ -69,7 +32,7 @@ return [
             'driver' => 'daily',
             'path' => storage_path('logs/laravel.log'),
             'level' => env('LOG_LEVEL', 'debug'),
-            'days' => env('LOG_DAILY_DAYS', 14),
+            'days' => 14,
             'replace_placeholders' => true,
         ],
 
@@ -82,18 +45,6 @@ return [
             'replace_placeholders' => true,
         ],
 
-        'papertrail' => [
-            'driver' => 'monolog',
-            'level' => env('LOG_LEVEL', 'debug'),
-            'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
-            'handler_with' => [
-                'host' => env('PAPERTRAIL_URL'),
-                'port' => env('PAPERTRAIL_PORT'),
-                'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
-            ],
-            'processors' => [PsrLogMessageProcessor::class],
-        ],
-
         'stderr' => [
             'driver' => 'monolog',
             'level' => env('LOG_LEVEL', 'debug'),
@@ -105,28 +56,13 @@ return [
             'processors' => [PsrLogMessageProcessor::class],
         ],
 
-        'syslog' => [
-            'driver' => 'syslog',
-            'level' => env('LOG_LEVEL', 'debug'),
-            'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER),
-            'replace_placeholders' => true,
-        ],
-
-        'errorlog' => [
-            'driver' => 'errorlog',
-            'level' => env('LOG_LEVEL', 'debug'),
-            'replace_placeholders' => true,
+        'emergency' => [
+            'path' => storage_path('logs/laravel.log'),
         ],
 
         'null' => [
             'driver' => 'monolog',
             'handler' => NullHandler::class,
         ],
-
-        'emergency' => [
-            'path' => storage_path('logs/laravel.log'),
-        ],
-
     ],
-
 ];

+ 3 - 1
script/ansible/bin/deploy

@@ -1,9 +1,11 @@
 #!/bin/bash
 
+cd script/ansible/bin
+
 # Set default APP_VERSION if not provided
 if [ -z "$APP_VERSION" ]; then
     export APP_VERSION="latest"
 fi
 
 # Run the deploy playbook
-ansible-playbook ../deploy_playbook.yml -i ../inventory/hosts"$@"
+ansible-playbook ../deploy_playbook.yml -i ../inventory/hosts"$@"

+ 2 - 2
script/ansible/bin/frpc

@@ -1,4 +1,4 @@
 #!/bin/bash
-
+cd script/ansible/bin
 # Run the frpc playbook
-ansible-playbook ../frpc_playbook.yml -i ../inventory/hosts "$@"
+ansible-playbook ../frpc_playbook.yml -i ../inventory/hosts "$@"

+ 26 - 0
script/bin/mylog

@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# log -c 清除日志
+# log -t 即tail -f -n 5000日志
+# log -l 即less 日志
+# log 直接回车或 -h,则打印使用方法
+
+if [ "$1" = "-c" ]; then
+    echo "clear log..."
+    > storage/logs/laravel.log
+    exit 0
+fi
+
+if [ "$1" = "-t" ]; then
+    tail -f -n 5000 storage/logs/laravel.log
+    exit 0
+fi
+
+if [ "$1" = "-l" ]; then
+    shift
+    less storage/logs/laravel.log
+    exit 0
+fi
+
+echo "usage: log [-c|-t|-l|-h]"
+exit 0