feat(log): 全面重构日志系统,支持日志级别、去除ANSI乱码并抑制高频轮询
This commit is contained in:
@@ -10,13 +10,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"affiliate_dash/internal/model"
|
||||
"affiliate_dash/internal/pkg/applog"
|
||||
"affiliate_dash/internal/pkg/timeutil"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -325,13 +325,13 @@ func (s *CallbackService) dispatchOne(ctx context.Context, id uint) (bool, bool,
|
||||
|
||||
resp, err := s.httpClient.Do(req)
|
||||
if err != nil {
|
||||
log.Printf("[callback] push fail event=%s event_id=%s merchant_id=%d url=%s err=%s", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, truncateCallbackError(err.Error()))
|
||||
applog.Warnf("[callback] push fail event=%s event_id=%s merchant_id=%d url=%s err=%s", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, truncateCallbackError(err.Error()))
|
||||
return false, true, s.recordCallbackFailure(delivery, 0, truncateCallbackError(err.Error()))
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
|
||||
if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices {
|
||||
log.Printf("[callback] push ok event=%s event_id=%s merchant_id=%d url=%s status=%d", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, resp.StatusCode)
|
||||
applog.Infof("[callback] push ok event=%s event_id=%s merchant_id=%d url=%s status=%d", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, resp.StatusCode)
|
||||
return true, true, s.db.Model(&model.CallbackDelivery{}).Where("id = ?", delivery.ID).Updates(map[string]interface{}{
|
||||
"status": model.CallbackDeliveryDelivered,
|
||||
"attempts": delivery.Attempts + 1,
|
||||
@@ -340,7 +340,7 @@ func (s *CallbackService) dispatchOne(ctx context.Context, id uint) (bool, bool,
|
||||
"delivered_at": time.Now(),
|
||||
}).Error
|
||||
}
|
||||
log.Printf("[callback] push fail event=%s event_id=%s merchant_id=%d url=%s status=%d body=%s", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, resp.StatusCode, truncateCallbackError(string(body)))
|
||||
applog.Warnf("[callback] push fail event=%s event_id=%s merchant_id=%d url=%s status=%d body=%s", delivery.Event, delivery.EventID, delivery.MerchantID, delivery.CallbackSubscription.URL, resp.StatusCode, truncateCallbackError(string(body)))
|
||||
return false, true, s.recordCallbackFailure(delivery, resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
@@ -367,9 +367,9 @@ func (s *CallbackService) Run(ctx context.Context) {
|
||||
for {
|
||||
successes, failures, err := s.DispatchDue(ctx, 50)
|
||||
if err != nil {
|
||||
log.Printf("[callback] dispatch error: %v", err)
|
||||
applog.Errorf("[callback] dispatch error: %v", err)
|
||||
} else if successes > 0 || failures > 0 {
|
||||
log.Printf("[callback] dispatch done successes=%d failures=%d", successes, failures)
|
||||
applog.Infof("[callback] dispatch done successes=%d failures=%d", successes, failures)
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
Reference in New Issue
Block a user