Commit a209ad367f1925259643d9c5a6b964d2ed882897
1 parent
5f8b3278
chore: redirect debug logs to file for docker env
Showing
2 changed files
with
15 additions
and
8 deletions
| @@ -185,15 +185,20 @@ class AuthService | @@ -185,15 +185,20 @@ class AuthService | ||
| 185 | /** | 185 | /** |
| 186 | * 获取微信手机号 | 186 | * 获取微信手机号 |
| 187 | */ | 187 | */ |
| 188 | + private function logDebug($msg) | ||
| 189 | + { | ||
| 190 | + file_put_contents(__DIR__ . '/debug.log', "[" . date('Y-m-d H:i:s') . "] " . $msg . "\n", FILE_APPEND); | ||
| 191 | + } | ||
| 192 | + | ||
| 188 | private function getPhoneNumber($phoneCode) | 193 | private function getPhoneNumber($phoneCode) |
| 189 | { | 194 | { |
| 190 | $appId = $this->config['wechat']['app_id']; | 195 | $appId = $this->config['wechat']['app_id']; |
| 191 | $appSecret = $this->config['wechat']['app_secret']; | 196 | $appSecret = $this->config['wechat']['app_secret']; |
| 192 | 197 | ||
| 193 | - echo "Debug: Checking WeChat Config - AppID: {$appId}, SecretLen: " . strlen($appSecret) . "\n"; | 198 | + $this->logDebug("Checking WeChat Config - AppID: {$appId}, SecretLen: " . strlen($appSecret)); |
| 194 | 199 | ||
| 195 | if (empty($appId) || empty($appSecret)) { | 200 | if (empty($appId) || empty($appSecret)) { |
| 196 | - echo "Debug: AppID or Secret is empty!\n"; | 201 | + $this->logDebug("AppID or Secret is empty!"); |
| 197 | return null; // 开发模式不支持 | 202 | return null; // 开发模式不支持 |
| 198 | } | 203 | } |
| 199 | 204 | ||
| @@ -205,11 +210,11 @@ class AuthService | @@ -205,11 +210,11 @@ class AuthService | ||
| 205 | ]); | 210 | ]); |
| 206 | 211 | ||
| 207 | $tokenRaw = file_get_contents($tokenUrl); | 212 | $tokenRaw = file_get_contents($tokenUrl); |
| 208 | - echo "Debug: Access Token Raw Response: {$tokenRaw}\n"; | 213 | + $this->logDebug("Access Token Raw Response: {$tokenRaw}"); |
| 209 | 214 | ||
| 210 | $tokenRes = json_decode($tokenRaw, true); | 215 | $tokenRes = json_decode($tokenRaw, true); |
| 211 | if (empty($tokenRes['access_token'])) { | 216 | if (empty($tokenRes['access_token'])) { |
| 212 | - echo "Debug: Failed to get access token.\n"; | 217 | + $this->logDebug("Failed to get access token."); |
| 213 | return null; | 218 | return null; |
| 214 | } | 219 | } |
| 215 | 220 | ||
| @@ -223,7 +228,7 @@ class AuthService | @@ -223,7 +228,7 @@ class AuthService | ||
| 223 | ] | 228 | ] |
| 224 | ])); | 229 | ])); |
| 225 | 230 | ||
| 226 | - echo "Debug: Phone Number Raw Response: {$phoneRaw}\n"; | 231 | + $this->logDebug("Phone Number Raw Response: {$phoneRaw}"); |
| 227 | 232 | ||
| 228 | $phoneRes = json_decode($phoneRaw, true); | 233 | $phoneRes = json_decode($phoneRaw, true); |
| 229 | 234 | ||
| @@ -231,7 +236,7 @@ class AuthService | @@ -231,7 +236,7 @@ class AuthService | ||
| 231 | return $phoneRes['phone_info']['purePhoneNumber']; | 236 | return $phoneRes['phone_info']['purePhoneNumber']; |
| 232 | } | 237 | } |
| 233 | 238 | ||
| 234 | - echo "Debug: Failed to parse phone number from response.\n"; | 239 | + $this->logDebug("Failed to parse phone number from response."); |
| 235 | return null; | 240 | return null; |
| 236 | } | 241 | } |
| 237 | 242 |
| @@ -77,9 +77,11 @@ $ws_worker->onWorkerStart = function ($worker) use ($config) { | @@ -77,9 +77,11 @@ $ws_worker->onWorkerStart = function ($worker) use ($config) { | ||
| 77 | $ws_port = $config['server']['websocket_port']; | 77 | $ws_port = $config['server']['websocket_port']; |
| 78 | echo "Relay Server Started on {$ws_host}:{$ws_port}\n"; | 78 | echo "Relay Server Started on {$ws_host}:{$ws_port}\n"; |
| 79 | 79 | ||
| 80 | - // Debug: Check WeChat Config | 80 | + // Debug: Check WeChat Config (Log to file for Docker) |
| 81 | $appId = $config['wechat']['app_id'] ?? 'Not Set'; | 81 | $appId = $config['wechat']['app_id'] ?? 'Not Set'; |
| 82 | - echo "Loaded WeChat AppID: {$appId}\n"; | 82 | + $logMsg = "[" . date('Y-m-d H:i:s') . "] Startup - Loaded WeChat AppID: {$appId}\n"; |
| 83 | + file_put_contents(__DIR__ . '/debug.log', $logMsg, FILE_APPEND); | ||
| 84 | + echo $logMsg; // Keep echo just in case | ||
| 83 | 85 | ||
| 84 | // Heartbeat check | 86 | // Heartbeat check |
| 85 | $check_interval = $config['heartbeat']['check_interval']; | 87 | $check_interval = $config['heartbeat']['check_interval']; |
Please
register
or
login
to post a comment