Commit a209ad367f1925259643d9c5a6b964d2ed882897

Authored by 谭苏航
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 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 193 private function getPhoneNumber($phoneCode)
189 194 {
190 195 $appId = $this->config['wechat']['app_id'];
191 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 200 if (empty($appId) || empty($appSecret)) {
196   - echo "Debug: AppID or Secret is empty!\n";
  201 + $this->logDebug("AppID or Secret is empty!");
197 202 return null; // 开发模式不支持
198 203 }
199 204
... ... @@ -205,11 +210,11 @@ class AuthService
205 210 ]);
206 211
207 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 215 $tokenRes = json_decode($tokenRaw, true);
211 216 if (empty($tokenRes['access_token'])) {
212   - echo "Debug: Failed to get access token.\n";
  217 + $this->logDebug("Failed to get access token.");
213 218 return null;
214 219 }
215 220
... ... @@ -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 233 $phoneRes = json_decode($phoneRaw, true);
229 234
... ... @@ -231,7 +236,7 @@ class AuthService
231 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 240 return null;
236 241 }
237 242
... ...
... ... @@ -77,9 +77,11 @@ $ws_worker->onWorkerStart = function ($worker) use ($config) {
77 77 $ws_port = $config['server']['websocket_port'];
78 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 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 86 // Heartbeat check
85 87 $check_interval = $config['heartbeat']['check_interval'];
... ...
Please register or login to post a comment