refactor(logging): унифицировать stdlib log.* в logx по client/cmd

internal/client/captcha, captcha/manual, dnsdial: добавить package-level Log +
SetLogger; убрать прямой обход -debug через stdlib log.Printf. cmd/{client,
server}/main.go: сначала строить logger, весь вывод через logger.{Info,Warn,
Error}f; оставлен один log.Fatalf только для сбоя разбора конфига до логгера.
dnsdial: log.Panicf → panic(fmt.Sprintf).

Исправлены уровни:
- vkauth/token.go: пути [FATAL] теперь Errorf; Auto/Manual captcha failed →
  Warnf; ignored-cleanup-error → Debugf.
- vkauth/client.go: HandleAuthError/cache invalidated → Warnf; throttle wait →
  Debugf; Failed-with-client_id → Warnf.
- udprelay: "Backing off 60s" + SetDeadline failed → Warnf.
- captcha: PoW/show_type/check status/debug_info → Debugf; endSession/close-body/
  script-drift → Warnf.

Префиксы нормализованы к [STREAM %d] [Pkg] msg / [Pkg] msg.
This commit is contained in:
samosvalishe committed 2026-05-20 11:26:21 +03:00
1 parent 52e7cb83e6
commit 9d7d754740
11 files changed
+146 -112

No files matched your search

+3 -4
View File
@@ -3,7 +3,6 @@ package vkauth
import (
"context"
"fmt"
"log"
"github.com/cacggghp/vk-turn-proxy/internal/client/browserprofile"
"github.com/cacggghp/vk-turn-proxy/internal/client/captcha"
@@ -21,7 +20,7 @@ func DefaultAutoSolve(
client tlsclient.HttpClient,
profile browserprofile.Profile,
) (string, error) {
log.Printf("[STREAM %d] [Captcha] Solving captcha...", streamID)
captcha.Log.Infof("[STREAM %d] [Captcha] Solving captcha...", streamID)
if captchaErr.SessionToken == "" {
return "", fmt.Errorf("no session_token in redirect_uri for auto-solve")
@@ -32,7 +31,7 @@ func DefaultAutoSolve(
var savedProfile *browserprofile.Saved
if sp, err := browserprofile.Load(); err == nil {
log.Printf("[STREAM %d] [Captcha] Using saved real browser profile", streamID)
captcha.Log.Infof("[STREAM %d] [Captcha] Using saved real browser profile", streamID)
savedProfile = sp
profile = sp.Profile
}
@@ -41,6 +40,6 @@ func DefaultAutoSolve(
if err != nil {
return "", err
}
log.Printf("[STREAM %d] [Captcha] solver succeeded", streamID)
captcha.Log.Infof("[STREAM %d] [Captcha] solver succeeded", streamID)
return successToken, nil
}
+6 -6
View File
@@ -156,12 +156,12 @@ func (c *Client) HandleAuthError(streamID int) bool {
count := cache.errorCount.Add(1)
cache.lastErrorTime.Store(now)
c.log.Infof("[STREAM %d] Auth error (cache=%d, count=%d/%d)", streamID, cacheID, count, MaxCacheErrors)
c.log.Warnf("[STREAM %d] [VK Auth] Auth error (cache=%d, count=%d/%d)", streamID, cacheID, count, MaxCacheErrors)
if count >= MaxCacheErrors {
c.log.Infof("[VK Auth] Multiple auth errors detected (%d), invalidating cache %d for stream %d...", count, cacheID, streamID)
c.log.Warnf("[VK Auth] Multiple auth errors (%d), invalidating cache %d for stream %d", count, cacheID, streamID)
cache.Invalidate()
c.log.Infof("[STREAM %d] [VK Auth] Credentials cache invalidated", streamID)
c.log.Warnf("[STREAM %d] [VK Auth] Credentials cache invalidated", streamID)
return true
}
return false
@@ -197,7 +197,7 @@ func (c *Client) fetchSerialized(ctx context.Context, link string, streamID int)
elapsed := time.Since(c.lastFetchTime)
if !c.lastFetchTime.IsZero() && elapsed < minInterval {
wait := minInterval - elapsed
c.log.Infof("[STREAM %d] [VK Auth] Throttling: waiting %v to prevent rate limit...", streamID, wait.Truncate(time.Millisecond))
c.log.Debugf("[STREAM %d] [VK Auth] Throttling: waiting %v to prevent rate limit", streamID, wait.Truncate(time.Millisecond))
select {
case <-ctx.Done():
return "", "", nil, ctx.Err()
@@ -225,14 +225,14 @@ func (c *Client) fetch(ctx context.Context, link string, streamID int) (string,
return user, pass, addrs, nil
}
lastErr = err
c.log.Infof("[STREAM %d] [VK Auth] Failed with client_id=%s: %v", streamID, creds.ClientID, err)
c.log.Warnf("[STREAM %d] [VK Auth] Failed with client_id=%s: %v", streamID, creds.ClientID, err)
if errors.Is(err, ErrCaptchaWaitRequired) || errors.Is(err, ErrFatalCaptchaNoStreams) {
return "", "", nil, err
}
es := err.Error()
if strings.Contains(es, "error_code:29") || strings.Contains(es, "error_code: 29") || strings.Contains(es, "Rate limit") {
c.log.Infof("[STREAM %d] [VK Auth] Rate limit detected, trying next credentials...", streamID)
c.log.Warnf("[STREAM %d] [VK Auth] Rate limit detected, trying next credentials", streamID)
}
}
return "", "", nil, fmt.Errorf("all VK credentials failed: %w", lastErr)
+12 -12
View File
@@ -75,7 +75,7 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
}
defer func() {
if closeErr := httpResp.Body.Close(); closeErr != nil {
c.log.Infof("close response body: %s", closeErr)
c.log.Warnf("[VK Auth] close response body: %s", closeErr)
}
}()
@@ -109,7 +109,7 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
// Token 1 -> getCallPreview (warmup, non-fatal).
data = fmt.Sprintf("vk_join_link=https://vk.com/call/join/%s&fields=photo_200&access_token=%s", link, token1)
if _, prevErr := doRequest(data, "https://api.vk.ru/method/calls.getCallPreview?v=5.275&client_id="+creds.ClientID); prevErr != nil {
c.log.Infof("[STREAM %d] [VK Auth] Warning: getCallPreview failed: %v", streamID, prevErr)
c.log.Warnf("[STREAM %d] [VK Auth] getCallPreview failed: %v", streamID, prevErr)
}
vkDelayRandom(200, 400)
@@ -130,10 +130,10 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
if captchaErr != nil && captchaErr.IsCaptcha() {
solveMode, hasSolveMode := CaptchaSolveModeForAttempt(attempt, c.manualOnly)
if !hasSolveMode {
c.log.Infof("[STREAM %d] [Captcha] No more solve modes available (attempt %d)", streamID, attempt+1)
c.log.Warnf("[STREAM %d] [Captcha] No more solve modes available (attempt %d)", streamID, attempt+1)
c.engageLockout(60 * time.Second)
if c.streamsFn() == 0 {
c.log.Infof("[STREAM %d] [FATAL] 0 connected streams and captcha solve modes exhausted.", streamID)
c.log.Errorf("[STREAM %d] [Captcha] FATAL: 0 connected streams and solve modes exhausted", streamID)
return "", "", nil, ErrFatalCaptchaNoStreams
}
return "", "", nil, ErrCaptchaWaitRequired
@@ -152,7 +152,7 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
if captchaErr.SessionToken != "" && captchaErr.RedirectURI != "" {
successToken, solveErr = solveFn(ctx, captchaErr, streamID, client, profile)
if solveErr != nil {
c.log.Infof("[STREAM %d] [Captcha] Auto captcha failed: %v", streamID, solveErr)
c.log.Warnf("[STREAM %d] [Captcha] Auto captcha failed: %v", streamID, solveErr)
}
} else {
solveErr = fmt.Errorf("missing fields for auto solve")
@@ -162,7 +162,7 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
solveErr = fmt.Errorf("manual captcha solver not configured")
break
}
c.log.Infof("[STREAM %d] [Captcha] Triggering manual captcha fallback...", streamID)
c.log.Infof("[STREAM %d] [Captcha] Triggering manual captcha fallback", streamID)
// Manual solver gets its own 3-min budget so a tight parent
// deadline doesn't cut user solve time. We still propagate
// parent cancellation (app shutdown) so the in-flight solver
@@ -187,12 +187,12 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
solveErr = res.err
if successToken != "" || captchaKey != "" {
if solveErr != nil {
c.log.Infof("[STREAM %d] [Captcha] Token received (ignoring cleanup error: %v)", streamID, solveErr)
c.log.Debugf("[STREAM %d] [Captcha] Token received (ignoring cleanup error: %v)", streamID, solveErr)
solveErr = nil
}
c.log.Infof("[STREAM %d] [Captcha] Successfully got token from browser", streamID)
c.log.Infof("[STREAM %d] [Captcha] Got token from browser", streamID)
} else if solveErr != nil {
c.log.Infof("[STREAM %d] [Captcha] manual solver returned error: %v", streamID, solveErr)
c.log.Warnf("[STREAM %d] [Captcha] Manual solver error: %v", streamID, solveErr)
}
case <-manualCtx.Done():
if errors.Is(manualCtx.Err(), context.DeadlineExceeded) {
@@ -205,15 +205,15 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
}
if solveErr != nil {
c.log.Infof("[STREAM %d] [Captcha] %s failed (attempt %d): %v", streamID, CaptchaSolveModeLabel(solveMode), attempt+1, solveErr)
c.log.Warnf("[STREAM %d] [Captcha] %s failed (attempt %d): %v", streamID, CaptchaSolveModeLabel(solveMode), attempt+1, solveErr)
nextSolveMode, hasNextSolveMode := CaptchaSolveModeForAttempt(attempt+1, c.manualOnly)
if hasNextSolveMode {
c.log.Infof("[STREAM %d] [Captcha] Falling back to %s...", streamID, CaptchaSolveModeLabel(nextSolveMode))
c.log.Infof("[STREAM %d] [Captcha] Falling back to %s", streamID, CaptchaSolveModeLabel(nextSolveMode))
continue
}
c.engageLockout(60 * time.Second)
if c.streamsFn() == 0 {
c.log.Infof("[STREAM %d] [FATAL] 0 connected streams and manual captcha failed/timed out.", streamID)
c.log.Errorf("[STREAM %d] [Captcha] FATAL: 0 connected streams and manual captcha failed/timed out", streamID)
return "", "", nil, ErrFatalCaptchaNoStreams
}
return "", "", nil, ErrCaptchaWaitRequired